How to remove lines starting with "C" using awk?

How to remove lines starting with "C" from a text file using awk ?

Any suggestions please.

+4
source share
4 answers

If the data is in the data.txt file, then

With awk :

 awk '!/^C/' data.txt 

With grep :

 grep -v ^C data.txt 

Show all lines without a "C" at the beginning.

^C means the letter "C" at the beginning of the line matches. ! in awk, and -v in grep denies matching.

+9
source

You can:

 awk '!/^C/{print $0}' 
+1
source

With sed :

 sed -i~ '/^C/d' inFile 
+1
source

This is elementary:

 awk '/^[^C]/' 

If you omit the {} section of awk, which means the same as {print} , or print a line. And // is the re-filter that applies to stdin. Only those lines matching the filter will be processed.

^[^C] is a regression of the regular. The first ^ is an anchor, this means the beginning of a line; and [^C] is a character class that means any character except C.

0
source

All Articles