Remove suffix from data in col 4 of csv file only (bash)

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have a csv file that col 4 of contains a suffux of "_1" that I need to remove without disturbing the other columns in the csv that may or may not contain a suffix of "_1".
CSV FILE OUTPUT:
DOM, PRO, CONFIG, CONFIG_CALL, PATH
xyz.com, Num1, Num1-V, Asp_tent_1, /bin/home
abc.com, Vel1, Vell-V, Asp_App, /ai/rev/sand
123.com, Xall, X-V, X_all_time_1, /ai/test
321.com, Zall, Z-V, Z_all_1, /bin/usr/home
...
WANTED OUTPUT:
DOM, PRO, CONFIG, CONFIG_CALL, PATH
xyz.com, Num1, Num1-V Asp_tent, /bin/home
abc.com, Vel1, Vell-V, Asp_App, /ai/rev/sand
123.com, Xall, X-V, X_all_time, /ai/test
321.com, Zall, Z-V, Z_all, /bin/usr/home
I have tried some awk, grep, tr attempts but no luck.
csv text-formatting
add a comment |Â
up vote
1
down vote
favorite
I have a csv file that col 4 of contains a suffux of "_1" that I need to remove without disturbing the other columns in the csv that may or may not contain a suffix of "_1".
CSV FILE OUTPUT:
DOM, PRO, CONFIG, CONFIG_CALL, PATH
xyz.com, Num1, Num1-V, Asp_tent_1, /bin/home
abc.com, Vel1, Vell-V, Asp_App, /ai/rev/sand
123.com, Xall, X-V, X_all_time_1, /ai/test
321.com, Zall, Z-V, Z_all_1, /bin/usr/home
...
WANTED OUTPUT:
DOM, PRO, CONFIG, CONFIG_CALL, PATH
xyz.com, Num1, Num1-V Asp_tent, /bin/home
abc.com, Vel1, Vell-V, Asp_App, /ai/rev/sand
123.com, Xall, X-V, X_all_time, /ai/test
321.com, Zall, Z-V, Z_all, /bin/usr/home
I have tried some awk, grep, tr attempts but no luck.
csv text-formatting
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a csv file that col 4 of contains a suffux of "_1" that I need to remove without disturbing the other columns in the csv that may or may not contain a suffix of "_1".
CSV FILE OUTPUT:
DOM, PRO, CONFIG, CONFIG_CALL, PATH
xyz.com, Num1, Num1-V, Asp_tent_1, /bin/home
abc.com, Vel1, Vell-V, Asp_App, /ai/rev/sand
123.com, Xall, X-V, X_all_time_1, /ai/test
321.com, Zall, Z-V, Z_all_1, /bin/usr/home
...
WANTED OUTPUT:
DOM, PRO, CONFIG, CONFIG_CALL, PATH
xyz.com, Num1, Num1-V Asp_tent, /bin/home
abc.com, Vel1, Vell-V, Asp_App, /ai/rev/sand
123.com, Xall, X-V, X_all_time, /ai/test
321.com, Zall, Z-V, Z_all, /bin/usr/home
I have tried some awk, grep, tr attempts but no luck.
csv text-formatting
I have a csv file that col 4 of contains a suffux of "_1" that I need to remove without disturbing the other columns in the csv that may or may not contain a suffix of "_1".
CSV FILE OUTPUT:
DOM, PRO, CONFIG, CONFIG_CALL, PATH
xyz.com, Num1, Num1-V, Asp_tent_1, /bin/home
abc.com, Vel1, Vell-V, Asp_App, /ai/rev/sand
123.com, Xall, X-V, X_all_time_1, /ai/test
321.com, Zall, Z-V, Z_all_1, /bin/usr/home
...
WANTED OUTPUT:
DOM, PRO, CONFIG, CONFIG_CALL, PATH
xyz.com, Num1, Num1-V Asp_tent, /bin/home
abc.com, Vel1, Vell-V, Asp_App, /ai/rev/sand
123.com, Xall, X-V, X_all_time, /ai/test
321.com, Zall, Z-V, Z_all, /bin/usr/home
I have tried some awk, grep, tr attempts but no luck.
csv text-formatting
edited Jul 12 at 19:12
Jeff Schaller
30.8k846104
30.8k846104
asked Jul 12 at 18:59
SSDdude
544
544
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
5
down vote
Using GNU awk:
awk -F, 'sub(/_1$/,"",$4)1' OFS=, input
add a comment |Â
up vote
0
down vote
Using SED:
sed -i 's/_1,/, /g' file.csv
2
without disturbing the other columns in the csv that may or may not contain a suffix of "_1"-- this will replace all _1's regardless of their position.
â Jeff Schaller
Jul 12 at 19:33
Yes. But I'm replacing_1,. So it do only for suffix..
â SivaPrasath
Jul 12 at 20:13
until field 2 or 3 ends in _1
â Jeff Schaller
Jul 12 at 20:14
Hey Jeff/Siva any update to this? I am finding "_1" removed from more that col 4. Just not sure how to mod this so it only affects entries in col 4 that end in "_1". Thanks!
â SSDdude
Jul 23 at 15:17
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
Using GNU awk:
awk -F, 'sub(/_1$/,"",$4)1' OFS=, input
add a comment |Â
up vote
5
down vote
Using GNU awk:
awk -F, 'sub(/_1$/,"",$4)1' OFS=, input
add a comment |Â
up vote
5
down vote
up vote
5
down vote
Using GNU awk:
awk -F, 'sub(/_1$/,"",$4)1' OFS=, input
Using GNU awk:
awk -F, 'sub(/_1$/,"",$4)1' OFS=, input
edited Jul 12 at 19:24
answered Jul 12 at 19:14
Jesse_b
10.1k22658
10.1k22658
add a comment |Â
add a comment |Â
up vote
0
down vote
Using SED:
sed -i 's/_1,/, /g' file.csv
2
without disturbing the other columns in the csv that may or may not contain a suffix of "_1"-- this will replace all _1's regardless of their position.
â Jeff Schaller
Jul 12 at 19:33
Yes. But I'm replacing_1,. So it do only for suffix..
â SivaPrasath
Jul 12 at 20:13
until field 2 or 3 ends in _1
â Jeff Schaller
Jul 12 at 20:14
Hey Jeff/Siva any update to this? I am finding "_1" removed from more that col 4. Just not sure how to mod this so it only affects entries in col 4 that end in "_1". Thanks!
â SSDdude
Jul 23 at 15:17
add a comment |Â
up vote
0
down vote
Using SED:
sed -i 's/_1,/, /g' file.csv
2
without disturbing the other columns in the csv that may or may not contain a suffix of "_1"-- this will replace all _1's regardless of their position.
â Jeff Schaller
Jul 12 at 19:33
Yes. But I'm replacing_1,. So it do only for suffix..
â SivaPrasath
Jul 12 at 20:13
until field 2 or 3 ends in _1
â Jeff Schaller
Jul 12 at 20:14
Hey Jeff/Siva any update to this? I am finding "_1" removed from more that col 4. Just not sure how to mod this so it only affects entries in col 4 that end in "_1". Thanks!
â SSDdude
Jul 23 at 15:17
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Using SED:
sed -i 's/_1,/, /g' file.csv
Using SED:
sed -i 's/_1,/, /g' file.csv
answered Jul 12 at 19:24
SivaPrasath
3,68311636
3,68311636
2
without disturbing the other columns in the csv that may or may not contain a suffix of "_1"-- this will replace all _1's regardless of their position.
â Jeff Schaller
Jul 12 at 19:33
Yes. But I'm replacing_1,. So it do only for suffix..
â SivaPrasath
Jul 12 at 20:13
until field 2 or 3 ends in _1
â Jeff Schaller
Jul 12 at 20:14
Hey Jeff/Siva any update to this? I am finding "_1" removed from more that col 4. Just not sure how to mod this so it only affects entries in col 4 that end in "_1". Thanks!
â SSDdude
Jul 23 at 15:17
add a comment |Â
2
without disturbing the other columns in the csv that may or may not contain a suffix of "_1"-- this will replace all _1's regardless of their position.
â Jeff Schaller
Jul 12 at 19:33
Yes. But I'm replacing_1,. So it do only for suffix..
â SivaPrasath
Jul 12 at 20:13
until field 2 or 3 ends in _1
â Jeff Schaller
Jul 12 at 20:14
Hey Jeff/Siva any update to this? I am finding "_1" removed from more that col 4. Just not sure how to mod this so it only affects entries in col 4 that end in "_1". Thanks!
â SSDdude
Jul 23 at 15:17
2
2
without disturbing the other columns in the csv that may or may not contain a suffix of "_1" -- this will replace all _1's regardless of their position.â Jeff Schaller
Jul 12 at 19:33
without disturbing the other columns in the csv that may or may not contain a suffix of "_1" -- this will replace all _1's regardless of their position.â Jeff Schaller
Jul 12 at 19:33
Yes. But I'm replacing
_1, . So it do only for suffix..â SivaPrasath
Jul 12 at 20:13
Yes. But I'm replacing
_1, . So it do only for suffix..â SivaPrasath
Jul 12 at 20:13
until field 2 or 3 ends in _1
â Jeff Schaller
Jul 12 at 20:14
until field 2 or 3 ends in _1
â Jeff Schaller
Jul 12 at 20:14
Hey Jeff/Siva any update to this? I am finding "_1" removed from more that col 4. Just not sure how to mod this so it only affects entries in col 4 that end in "_1". Thanks!
â SSDdude
Jul 23 at 15:17
Hey Jeff/Siva any update to this? I am finding "_1" removed from more that col 4. Just not sure how to mod this so it only affects entries in col 4 that end in "_1". Thanks!
â SSDdude
Jul 23 at 15:17
add a comment |Â
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%2f454965%2fremove-suffix-from-data-in-col-4-of-csv-file-only-bash%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