How can I delete the rows that start with "C" from a text file using awk
?
Any suggestions please.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With