1

I have a CSV table structured as below (I aligned columns for clarity):

AAAA, BBBB,                CCCC, DDDD
EEEE, FFFF;1111,           GGGG, HHHH
IIII, JJJJ;2222;3333;4444, KKKK, LLLL

And in the second column I would like to remove everything after the first occurrence of a semi-colon, resulting in:

AAAA, BBBB, CCCC, DDDD
EEEE, FFFF, GGGG, HHHH
IIII, JJJJ, KKKK, LLLL

I've tried various awk commands inspired from here, here, and here, but can't quite get it.

I understand I could select the second column and edit it by awk -F, '{print $2}' file | cut -d ';' -f 1, but can't seem to figure out how to replace the second column with that command

1 Answer 1

3
$ awk '{sub(";[^,]+","")}1' file

or, perhaps better

$ sed -E 's/;[^,]+//' file
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.