How to delete the rows that start with “C” with aw

2019-04-30 02:13发布

问题:

How can I delete the rows that start with "C" from a text file using awk?

Any suggestions please.

回答1:

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.



回答2:

You may:

awk '!/^C/{print $0}'


回答3:

With sed:

sed -i~ '/^C/d' inFile


回答4:

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.



标签: shell awk