|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | 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. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Remove every third line from a file
I need to remove every second and every third line from a file. My idea was to do it in two operations. First every third line, then every second line. The problem is that i can't find out how to do it. I tried to look for some sed oneliners, but couldn't find any.
Suggestions? |
| Sponsored Links | |
|
|
|
#2
|
|||
|
|||
|
awk 'NR%3 != 0' filename
in the same way, change 3 as 2 to remove 2nd line from the file |
| Sponsored Links | ||
|
|
|
#3
|
||||
|
||||
|
Is this what you mean? Code:
$ cat bistru.txt line 1 line 2 line 3 line 4 line 5 line 6 line 7 line 8 line 9 $ sed -n 'p;N;N' bistru.txt line 1 line 4 line 7 $ Cheers ZB |
|
#4
|
|||
|
|||
|
Thanks, both worked perfectly!
BTW, zazzybob, i'm not able to understand the syntax rather well. Do You mind giving a short explanation? I understand '-n' and that 'p' overruns the '-n'. From man sed i found that 'n' or 'N' means that the next line is input into the pattern space, implying that the line is suppressed. Am i completely wrong here, or? |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Quote:
Code:
awk 'NR % 3 == 1' filename |
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to remove the first line from a flat file ? | xli | UNIX for Dummies Questions & Answers | 21 | 12-16-2008 12:37 AM |
| remove a line within a file | new2ss | UNIX for Dummies Questions & Answers | 3 | 11-23-2008 01:34 PM |
| How to remove FIRST Line of huge text file on Solaris | madoatz | UNIX for Dummies Questions & Answers | 5 | 06-23-2007 01:19 PM |
| How to remove last line of the file | mani_um | Shell Programming and Scripting | 3 | 05-14-2007 08:35 AM |
| Remove header(first line) and trailer(last line) in ANY given file | madhunk | Shell Programming and Scripting | 2 | 03-13-2006 02:36 PM |
|
|