I am trying to delete all commas from the first column of a text file. However, I need to preserve the character if it is not a comma. How can I do this with awk or sed? here is an example:


as you can see, I cannot simply delete the first column, as 2 digit numbers will be truncated.

  • 3
    Can you provide an example and what have you tried so far? – schrodigerscatcuriosity Jun 12 '19 at 17:58
  • 1
    Yes, please give us an example of your input so we know what we are working with. How are columns defined? Spaces? Tabs? Something else? Do you mean the 1st character of each line? – terdon Jun 12 '19 at 18:02
  • 1
    can you please explain what do you mean by first column? is the file content space saparated, or you just want to remove the first comma from each line? – sanjeev Jun 12 '19 at 18:03
  • column means first character of each row/line – john doe Jun 12 '19 at 18:13

With sed:

sed 's/^,//' file

This deletes the comma if it is the first character on each line.

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.