Mind5 Mind5 - 1 year ago 66
Linux Question

AWK- reading an exel file(CSV) and making another

i am using "awk" command to read my csv file, i want to use it with a condition, if the condition is valid i want to take the "row" not with all the colomns and write it in another csv file.

for example:

the CSV File:

fname lname id address street phone telephone

row1:myfname mylname 123 serlanka j12street 05666355 02365410



the condition: if the row have an id "123" -> then i want just fname, lname and id columns in the new csv.

i'v used awk command in my code.


zcat "$FileName" | awk -F'\t' '(($4 >=400) && ($4 <=599)) {Str="HTTP Error: " $4;print Str >> "New.csv"}'

how can i write the row or some information from the same row.


Answer Source

More or less add this to the end of your script:

$3 ~ /123/ {print $1,$2,$3 >> "New.csv"}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download