Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete the rows that start with "C" with awk?

Tags:

shell

awk

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

Any suggestions please.

like image 491
sagar Avatar asked Jun 20 '12 10:06

sagar


People also ask

How do you remove the first line in awk?

The following `awk` command uses the '-F' option and NR and NF to print the book names after skipping the first book. The '-F' option is used to separate the content of the file base on \t. NR is used to skip the first line, and NF is used to print the first column only.

How do I delete an awk record?

To delete line 1, use awk 'NR!= 1'. The default action is to print the line. All of your '{next} {print}' terms can be removed.

What does\ t do in awk?

Hang on and follow with me so you get the flavor of AWK. The characters "\t" Indicates a tab character so the output lines up on even boundries. The "$8" and "$3" have a meaning similar to a shell script. Instead of the eighth and third argument, they mean the eighth and third field of the input line.


1 Answers

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.

like image 185
Levon Avatar answered Nov 16 '22 03:11

Levon