Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete specific line

Status
Not open for further replies.

dbase77

Technical User
Apr 23, 2002
591
0
0
IE
Hi All,

How do I go about deleting specific line? Example, every 15 lines, I want to delete line. Thanks.
 
awk 'NR%15' /path/to/input > output

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi

Code:
sed '15~15d' /input/file > /output/file

[gray]# or[/gray]

awk 'NR%15' /input/file > /output/file

[gray]# or with GNU sed[/gray]

sed -i '15~15d' /input/file

Feherke.
 
Which flavor of sed admits this syntax: '15~15d' ?
 
Hi,

I got error for both awk and sed.

using awk:
>>awk 'NR%88' file1 > /tmp/file2
awk: syntax error near line 1
awk: bailing out near line 1

using sed:
>>sed '15~15d' file1 > /tmp/file2
Unrecognized command: 15~15d

Any ideas? Thanks.
 
Try nawk instead of awk.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
GNU sed
Code:
The following address types are supported:

[COLOR=blue]number[/color] Match only the specified line [COLOR=blue]number[/color].

[COLOR=blue]first[/color]~[COLOR=blue]step[/color]
       Match  every  [COLOR=blue]step[/color]'th  line starting with line [COLOR=blue]first[/color].  For example, ``sed -n
       1~2p'' will print all the odd-numbered lines in the input  stream,  and  the
       address  2~5 will match every fifth line, starting with the second. (This is
       an extension.)


Jean-Pierre.
 
Hi,

Thanks. nawk is working. I wonder why sed doesnt work. I guess I stick with nawk for now. Thanks again.
 
I wonder why sed doesnt work
In fact the "sed" solution provided isn't POSIX compliant (ie standard) but GNU extended.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top