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.

5

Using GNU awk:

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

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 '18 at 19:33
  • Yes. But I'm replacing _1, . So it do only for suffix.. – msp9011 Jul 12 '18 at 20:13
  • until field 2 or 3 ends in _1 – Jeff Schaller Jul 12 '18 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 '18 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.