It is currently Tue, 17 May 2022 01:13:33 GMT



 
Author Message
 sed : an expression for the last but one line
Hello

I'm using sed to make philters. I can parse all lines using the prefix
1,$ but I'd like to avoid the first and last line from the command focus.
Is there a symbol or an expression for the last but one line ( $-1 doesn't
work) ?

sir Alex



 Tue, 18 Feb 2003 19:40:53 GMT   
 sed : an expression for the last but one line
On Fri, 1 Sep 2000 13:40:53 +0200, "Fran?ois"

You might try explicitly dropping the first and last lines:
sed '1,d; $,d'

Dave

+---------------------+---------------+
|nojunkm...@nospam.com| mindspring.com|
|nos...@nojunkmail.com| davegrantier@ |
+---------------------+---------------+



 Thu, 20 Feb 2003 07:52:40 GMT   
 sed : an expression for the last but one line
In article <8oo4mf$ci...@ons.mc2.renault.fr>,
        You can negate addresses with the ! command:

$ sed '$!s/:/%/g' /etc/passwd

        .  That says to match the last line, and then execute the
command shown for every line _except_ that matched line.  Getting every line
except the first _and_ the last one is a little trickier; the easiest way I
can think of is

$ sed '1{
p;d
$!s/:/%/g'

        , which does the same thing, but first prints the first line
untouched, and then deletes it from the pattern space.

        -- Sweth.

--
Sweth Chandramouli ; <sw...@sweth.net>
<a href="http://www.sweth.net/legal/disc.html">*</a>



 Sat, 22 Feb 2003 14:54:03 GMT   
 sed : an expression for the last but one line

A simpler way would be:
  sed '1b
       $!s/:/%/g'

                --Ken Pizzini



 Sat, 22 Feb 2003 18:14:17 GMT   
 
   [ 4 post ] 

Similar Threads

1. One last line - one last time

2. what sed command to print the first line and the last line

3. sed expression for truncating line length

4. SED question (1st line that matches expression)

5. sed omits last line

6. sed, remove last new line

7. sed 'n' Repeats Last Line

8. sed: last line is omitted if no \n at the end of file

9. sed: print first 2 and last 2 lines?


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software