Home > Back-end >  Remove negative number from Column data in CSV file using shell command
Remove negative number from Column data in CSV file using shell command

Time:10-08

I have following sample CSV file with one of column have negative number or null (no value), how can negative sign remove from file using shell command and stored as positive number at same place.

sample1,COST,USD,-67,2021-09-20T07
sample2,COST,USD,-97,2021-09-20T07
sample3,COST,USD,-7,2021-09-20T07
sample4,COST,USD, ,2021-09-20T07
sample5,COST,USD, ,2021-09-20T07
sample6,COST,USD,-9,2021-09-20T07

Thanks, Ajit

CodePudding user response:

Something like

awk '
    BEGIN { FS=OFS="," }
    $4 < 0 { $4 = -$4 }
    1' input.csv

assuming your CSV data is trivial (no commas or newlines in fields or other complicated stuff)

  • Related