1

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:

,2,x.x.x.x
,1,x.x.x.x
,1,x.x.x.x
,1,x.x.x.x
,6,x.x.x.x
21,x.x.x.x
,1,x.x.x.x
,1,x.x.x.x

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

4
  • 3
    Can you provide an example and what have you tried so far? Jun 12, 2019 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, 2019 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? Jun 12, 2019 at 18:03
  • column means first character of each row/line
    – john doe
    Jun 12, 2019 at 18:13

1 Answer 1

3

With sed:

sed 's/^,//' file

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .