sed conditional delete of lines

November 8, 2010 at 08:37:22
Specs: HP-UX B.11.11 U
Sorry I think there may be a parked one of these?

I'm a sed newbie and would appreciate some help

This is my file:
cat in3.txt
hed, hed2, hed3, hed4, hed5, hed6

1,field 1, field 2, field 3, field 4, last field
1,field 1, field 2, field 3, field 4, last field
2,field 1, field 2, field 3, field 4, last field
1,field 1, field 2, field 3, field 4, last field
2,field 1, field 2, field 3, field 4, last field
1,field 1, field 2, field 3, field 4, last field
1,field 1, field 2, field 3, field 4, last field
2,field 1, field 2, field 3, field 4, last field

I want to delete all lines which start with 2

Have tried many options but am failing miserably!

removes blank:
hqcf01-efin-MAINA>sed '/^2*$/d' in3.txt
hed, hed2, hed3, hed4, hed5, hed6
1,field 1, field 2, field 3, field 4, last field
1,field 1, field 2, field 3, field 4, last field
2,field 1, field 2, field 3, field 4, last field
1,field 1, field 2, field 3, field 4, last field
2,field 1, field 2, field 3, field 4, last field
1,field 1, field 2, field 3, field 4, last field
1,field 1, field 2, field 3, field 4, last field
2,field 1, field 2, field 3, field 4, last field

sed '/^[2]*$/d' in3.txt
hed, hed2, hed3, hed4, hed5, hed6
1,field 1, field 2, field 3, field 4, last field
1,field 1, field 2, field 3, field 4, last field
2,field 1, field 2, field 3, field 4, last field
1,field 1, field 2, field 3, field 4, last field
2,field 1, field 2, field 3, field 4, last field
1,field 1, field 2, field 3, field 4, last field
1,field 1, field 2, field 3, field 4, last field
2,field 1, field 2, field 3, field 4, last field


See More: sed conditional delete of lines

Report •

#1
November 8, 2010 at 09:22:56
Haven't got a sed answer; but I can use a simple grep to get what I need, thanks.
If there is a simple sed I wouldn't mind knowing the answer, though.

grep -v '^2' in3.txt > out3.txt

>cat in3.txt
hed, hed2, hed3, hed4, hed5, hed6

1,field 1, field 2, field 3, field 4, last field
1,field 1, field 2, field 3, field 4, last field
2,field 1, field 2, field 3, field 4, last field
1,field 1, field 2, field 3, field 4, last field
2,field 1, field 2, field 3, field 4, last field
1,field 1, field 2, field 3, field 4, last field
1,field 1, field 2, field 3, field 4, last field
2,field 1, field 2, field 3, field 4, last field
>cat out3.txt
hed, hed2, hed3, hed4, hed5, hed6

1,field 1, field 2, field 3, field 4, last field
1,field 1, field 2, field 3, field 4, last field
1,field 1, field 2, field 3, field 4, last field
1,field 1, field 2, field 3, field 4, last field
1,field 1, field 2, field 3, field 4, last field


Report •

#2
November 8, 2010 at 10:09:47
You almost had it:

sed '/^2/d' datafile


Report •

#3
November 8, 2010 at 10:14:13
Thanks, Nails

Trust me to try and be too complicated!

>sed '/^2/d' in3.txt
hed, hed2, hed3, hed4, hed5, hed6

1,field 1, field 2, field 3, field 4, last field
1,field 1, field 2, field 3, field 4, last field
1,field 1, field 2, field 3, field 4, last field
1,field 1, field 2, field 3, field 4, last field
1,field 1, field 2, field 3, field 4, last field


Report •
Related Solutions


Ask Question