Remove column using awk Remove column using awk unix unix

Remove column using awk


To print all but first 3 columns use the following approach:

For the input PURCHASE_testing.csv file contents:

Account num|Car|Type|Name|Class|Price 0101 |A |Honda| Fara |A|rm20k 1234 |B | Proton|Afiq |B|rm40k

awk -F"|" '{$1=$2=$3=""; print $0}' PURCHASE_testing.csv > testing.csv

Now, the testing.csv file contents should look like:

Name Class Price  Fara  A rm20k Afiq  B rm40k


try this -

awk 'BEGIN{FS="|"} {print $4,$5,substr($6,1,4)}' fName Class PricFara  A rm20Afiq  B rm40

Explanation : substr($6,1,4) fetching 1 to 4 character from column 6.