![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Strip one line from 2 blank lines in a file | tipsy | Shell Programming and Scripting | 6 | 06-23-2008 09:14 AM |
| strip first 4 and last 2 lines from a file using perl | meghana | Shell Programming and Scripting | 10 | 02-01-2008 09:01 PM |
| Append Header and Trailer | balzzz | UNIX for Dummies Questions & Answers | 2 | 01-06-2008 08:19 AM |
| How to count lines - ignoring blank lines and commented lines | kthatch | UNIX for Dummies Questions & Answers | 6 | 05-25-2007 02:21 AM |
| Total of lines w/out header and footer incude for a file | gzs553 | Shell Programming and Scripting | 1 | 11-16-2006 07:42 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Code:
sed -e :a -e '$d;N;2,4ba' -e 'P;D' N appends second line to pattern space. Since second line is in pattern space 2,4ba makes control to shift to -e :a. Then N appends third line to pattern space. 2,4ba makes control shift to -e :a. Then N appends fourth line to pattern space and control is shifted to -e :a. If the fourth line is the last line then $d deletes all the lines in the pattern space else N appends fifth line to pattern space. Now 2,4ba is not satisfied then P is executed to print the first line in pattern space and this line is then deleted by D command. Then control is shifted to start of commands. If fifth line is last line then $d deletes all the lines in the pattern space and continues to till the end of file. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|