I have a CSV file that I would like to make bulk changes on column 1.
If V change to Outbound and if N change to Inbound
Call Type Call Cause Customer Identifier Telephone Number Dialled Call Date Call
N 2 1 1 15/12/2022 10:59:09 53
N 2 1 1 15/12/2022 10:55:44 264
V 2 1 1 15/12/2022 10:55:16 295
N 2 1 1 15/12/2022 10:59:02 70
N 2 1 1 15/12/2022 10:52:40 453
V 2 1 1 15/12/2022 10:59:32 41
N 2 1 1 15/12/2022 10:28:21 1915
I think AWK might be the tool for the job but I'm not how to achieve this and will be using this on linux.
Can anyone help?
CodePudding user response:
Instead of awk you should use sed for this: https://www.gnu.org/software/sed/manual/sed.html
For example, this would output the file with all the N's (at the beginning of each line) changed to "Inbound":
sed 's ^N Inbound g' calls.csv
CodePudding user response:
awk '$1=="V" {$1="Outbound"} $1=="N" {$1="Inbound"} {print}' first.csv
Where first.csv
is your csv file.
CodePudding user response:
Use an inline if/else to set the first column ($1
) to a new value, then print
the whole row:
awk -F '[[:space:]]' '{ $1 = ($1 == "N" ? "Inbound" : "Outbound"); print $0; }' inputfile.txt
Inbound 2 1 1 15/12/2022 10:59:09 53
Inbound 2 1 1 15/12/2022 10:55:44 264
Outbound 2 1 1 15/12/2022 10:55:16 295
Inbound 2 1 1 15/12/2022 10:59:02 70
Inbound 2 1 1 15/12/2022 10:52:40 453
Outbound 2 1 1 15/12/2022 10:59:32 41
Inbound 2 1 1 15/12/2022 10:28:21 1915