1

I need to add a new string end of each line.

sample data:
1.0.64.0/18
1.1.8.0/24
1.119.0.0/17
1.120.0.0/13

I am trying with this sed 's/$/|COUNTRY/'

1.0.64.0/18^M|COUNTRY
1.1.8.0/24^M|COUNTRY
1.119.0.0/17^M|COUNTRY
1.120.0.0/13^M|COUNTRY

As you can see I am getting ^M character. how can I get rid of this ^M character? Thanks in advance.

  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww Feb 16 '18 at 07:41

1 Answers1

2

dos2unix utility is your friend. It is specially there to remove those(carriage) characters.

In case of you don't have dos2unix then use following commands:

tr -d '\r' < Input_file > temp_file && mv temp_file Input_file
OR
awk '{gsub(/\r/,"")} 1' Input_file
RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93