База знаний

Linux - How to only keep X data

Firstly to start this you need to convert your .csv into a .txt

mv filename.csv  filename.txt

If you only wanted to keep fields that contain the word "dogs" or "cats" then you would run the following. $1 represents the field number

< filename.txt awk 'BEGIN {FS=","} tolower($1~/dogs|cats/' > newfilename.txt

If you also want to keep X data in either of the first or second columns you can run this command (replace smith and john with your keywords)
< filename.txt awk 'BEGIN {FS="\",\""} tolower($1~/smith|john/||$2~/smith|john/' > newfilename.txt

Этот ответ был полезен?

 Распечатать статью

Также читают

Linux - How to split large file

For this example we will split a large .csv into multiple files each "X" megabytes in size....

Linux - Only keep certain country data

< FileToExtract.csv awk 'BEGIN {FS=","} tolower($19)~/usa|united states/' > USAList.txtThis...

Linux - How to combine multiple .csv files

To combine multiple files with the letters "2014" and "2015" in their name run the following...

Linux - Delete .csv column

Before you start you need to install Ubuntu - sudo apt-get install libtext-csv-perl CentOs -...

Linux - How to delete .csv file containing "X" data

After extracting the .csv.gz files you can delete certain unwanted data by running the following...