1

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.

2 Answers 2

5

Using GNU awk:

awk -F, '{sub(/_1$/,"",$4)}1' OFS=, input
0
0

Using SED:

sed -i 's/_1,/,  /g' file.csv
4
  • 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. Commented Jul 12, 2018 at 19:33
  • Yes. But I'm replacing _1, . So it do only for suffix.. Commented Jul 12, 2018 at 20:13
  • until field 2 or 3 ends in _1 Commented Jul 12, 2018 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! Commented Jul 23, 2018 at 15:17

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.