I have a csv file and want to edit just the first column containing title of scientific papers by deleting everything after the ";" sign.

So a typical title would have the following form:

long scientific title here;other stuff I want to delete including the semicolon (no space between ; and the text)

I want the title to look like this:

long scientific title here

How can I achieve that using either sed or awk (on macOS if this matters)?

  • 1
    do u want to delete all after the first semicolon in each row? – Siva Oct 11 '19 at 19:19
  • 1
    Just edited my question. – Til Hund Oct 11 '19 at 19:22
  • 1
    So if long scientific title here appears more than once you want to modify the first row it occurs in but leave any following rows alone entirely right? – jesse_b Oct 11 '19 at 19:43
  • Hi Jesse, I would like all titles in the first column to be treated the same way, so that everything behind a semicolon is removed. Not all titles have a ; but the vast majority does. – Til Hund Oct 11 '19 at 19:48
  • I gather your column separator is tab. – schrodigerscatcuriosity Oct 11 '19 at 19:59

If you want to remove everything after the first semicolon in each row:

With cut:

cut -d';' -f1 file
  • -d';' use semicolon as delimiter
  • -f1 print the first field

With awk:

awk -F';' '{ print $1 }' file

Similar to cut: Use semicolon as input field separator and print the first field.

With sed:

sed 's/;.*//' file

Substitute semicolon and any following characters with an empty string.


As it is the first column I think (GNU) sed is enough. Assuming that the column separators are tabs:

sed -E 's/^(.*);.*\t/\1\t/' file

Your OS contains many small and simple tools that do text processing. In this case I would use cut :

cut -d; -f1 <FILE >tmpfile && mv tmpfile FILE

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.