AWK: Insert copy of column in the middle of csv
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
Example csv:
AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH
Now i wan't a copy column 2 (BBB) and add it in front of column 3 so the file looks like:
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
awk
add a comment |Â
up vote
2
down vote
favorite
Example csv:
AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH
Now i wan't a copy column 2 (BBB) and add it in front of column 3 so the file looks like:
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
awk
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Example csv:
AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH
Now i wan't a copy column 2 (BBB) and add it in front of column 3 so the file looks like:
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
awk
Example csv:
AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH
Now i wan't a copy column 2 (BBB) and add it in front of column 3 so the file looks like:
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
awk
awk
asked Aug 31 at 9:08
T-One
536
536
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
7
down vote
accepted
$ cat test.txt
AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH
AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH
AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH
$ awk -F, '$2=$2","$21' OFS=, test.txt
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
1
much cleaner than my answer :)
â RobotJohnny
Aug 31 at 9:15
In this case I think this is enough: awk '$2=$2" "$21' test.txt
â Claes Wikner
Sep 1 at 22:47
add a comment |Â
up vote
3
down vote
awk 'print $1,$2,$2,$3,$4,$5,$6,$7,$8' file.csv
Example:
⤠echo "AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH" | awk 'print $1,$2,$2,$3,$4,$5,$6,$7,$8'
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
Thanks, that's a solution i already thought about but the real csv file has more then 50 fields so the print gets very long.
â T-One
Aug 31 at 9:15
1
check out @Kamaraj's answer, should do the trick for you
â RobotJohnny
Aug 31 at 9:16
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
7
down vote
accepted
$ cat test.txt
AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH
AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH
AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH
$ awk -F, '$2=$2","$21' OFS=, test.txt
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
1
much cleaner than my answer :)
â RobotJohnny
Aug 31 at 9:15
In this case I think this is enough: awk '$2=$2" "$21' test.txt
â Claes Wikner
Sep 1 at 22:47
add a comment |Â
up vote
7
down vote
accepted
$ cat test.txt
AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH
AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH
AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH
$ awk -F, '$2=$2","$21' OFS=, test.txt
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
1
much cleaner than my answer :)
â RobotJohnny
Aug 31 at 9:15
In this case I think this is enough: awk '$2=$2" "$21' test.txt
â Claes Wikner
Sep 1 at 22:47
add a comment |Â
up vote
7
down vote
accepted
up vote
7
down vote
accepted
$ cat test.txt
AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH
AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH
AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH
$ awk -F, '$2=$2","$21' OFS=, test.txt
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
$ cat test.txt
AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH
AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH
AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH
$ awk -F, '$2=$2","$21' OFS=, test.txt
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
answered Aug 31 at 9:11
Kamaraj
2,9081413
2,9081413
1
much cleaner than my answer :)
â RobotJohnny
Aug 31 at 9:15
In this case I think this is enough: awk '$2=$2" "$21' test.txt
â Claes Wikner
Sep 1 at 22:47
add a comment |Â
1
much cleaner than my answer :)
â RobotJohnny
Aug 31 at 9:15
In this case I think this is enough: awk '$2=$2" "$21' test.txt
â Claes Wikner
Sep 1 at 22:47
1
1
much cleaner than my answer :)
â RobotJohnny
Aug 31 at 9:15
much cleaner than my answer :)
â RobotJohnny
Aug 31 at 9:15
In this case I think this is enough: awk '$2=$2" "$21' test.txt
â Claes Wikner
Sep 1 at 22:47
In this case I think this is enough: awk '$2=$2" "$21' test.txt
â Claes Wikner
Sep 1 at 22:47
add a comment |Â
up vote
3
down vote
awk 'print $1,$2,$2,$3,$4,$5,$6,$7,$8' file.csv
Example:
⤠echo "AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH" | awk 'print $1,$2,$2,$3,$4,$5,$6,$7,$8'
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
Thanks, that's a solution i already thought about but the real csv file has more then 50 fields so the print gets very long.
â T-One
Aug 31 at 9:15
1
check out @Kamaraj's answer, should do the trick for you
â RobotJohnny
Aug 31 at 9:16
add a comment |Â
up vote
3
down vote
awk 'print $1,$2,$2,$3,$4,$5,$6,$7,$8' file.csv
Example:
⤠echo "AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH" | awk 'print $1,$2,$2,$3,$4,$5,$6,$7,$8'
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
Thanks, that's a solution i already thought about but the real csv file has more then 50 fields so the print gets very long.
â T-One
Aug 31 at 9:15
1
check out @Kamaraj's answer, should do the trick for you
â RobotJohnny
Aug 31 at 9:16
add a comment |Â
up vote
3
down vote
up vote
3
down vote
awk 'print $1,$2,$2,$3,$4,$5,$6,$7,$8' file.csv
Example:
⤠echo "AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH" | awk 'print $1,$2,$2,$3,$4,$5,$6,$7,$8'
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
awk 'print $1,$2,$2,$3,$4,$5,$6,$7,$8' file.csv
Example:
⤠echo "AAA, BBB, CCC, DDD, EEE, FFF, GGG, HHH" | awk 'print $1,$2,$2,$3,$4,$5,$6,$7,$8'
AAA, BBB, BBB, CCC, DDD, EEE, FFF, GGG, HHH
answered Aug 31 at 9:10
RobotJohnny
702216
702216
Thanks, that's a solution i already thought about but the real csv file has more then 50 fields so the print gets very long.
â T-One
Aug 31 at 9:15
1
check out @Kamaraj's answer, should do the trick for you
â RobotJohnny
Aug 31 at 9:16
add a comment |Â
Thanks, that's a solution i already thought about but the real csv file has more then 50 fields so the print gets very long.
â T-One
Aug 31 at 9:15
1
check out @Kamaraj's answer, should do the trick for you
â RobotJohnny
Aug 31 at 9:16
Thanks, that's a solution i already thought about but the real csv file has more then 50 fields so the print gets very long.
â T-One
Aug 31 at 9:15
Thanks, that's a solution i already thought about but the real csv file has more then 50 fields so the print gets very long.
â T-One
Aug 31 at 9:15
1
1
check out @Kamaraj's answer, should do the trick for you
â RobotJohnny
Aug 31 at 9:16
check out @Kamaraj's answer, should do the trick for you
â RobotJohnny
Aug 31 at 9:16
add a comment |Â
Â
draft saved
draft discarded
Â
draft saved
draft discarded
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f465964%2fawk-insert-copy-of-column-in-the-middle-of-csv%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password