How can I delete the rows that start with "C" from a text file using awk
?
Any suggestions please.
How can I delete the rows that start with "C" from a text file using awk
?
Any suggestions please.
If data is in file data.txt
, then
With awk
:
awk '!/^C/' data.txt
With grep
:
grep -v ^C data.txt
Display all lines without "C" at the start.
^C
means to match letter "C" at start of line. !
in awk, and -v
in grep negate the match.
You may:
awk '!/^C/{print $0}'
With sed
:
sed -i~ '/^C/d' inFile
That is elementary:
awk '/^[^C]/'
When you omit {}
section of an awk command that means the same as {print}
or print the line. And //
is re-filter that is applied to stdin. Only that lines will be processed that conform to the filter.
^[^C]
is a regula rexpression. The first ^
is an anchor, it means the beginning of the line; and [^C]
is a symbol class that means any character except C.