Awk

How to Use Awk to Remove the First Line of a File

Awk is a versatile pattern scanning application, installed by default on most Linux distributions. If you have Ubuntu, Debian, or openSUSE, it's already installed. You can use Awk to easily remove the first line or row of a text file. To do so, just run the following one-liner command. Make sure to specify the source file, and the file you want the processed data to go to:

awk '{if(NR>1)print}' source_file.txt > processed_file.txt

 

How to Remove Commas Inside of Quotes From a CSV or Text File on Linux with Awk

Let's say you have a CSV file that you would like to open in Excel or LibreOffice Calc to analzye. You find out the formatting is broken because there is a column that has quoted text with a comma in it:

Name, Country, City

Jason, US, Memphis

David, US, Little Rock

"Karam, Sage", US, Nazareth

As you can see, this may cause a problem when importing the file into your spreadsheet application as the 4th row has 4 commas, and the others only have 3.

This is easy to fix using Awk. Simply run this one-liner command, specifying your source file, and then a new file to output it to:

awk -F'"' -v OFS='' '{ for (i=2; i<=NF; i+=2) gsub(",", "", $i) } 1' source_file.csv >processed_file.csv

Subscribe to Awk