spirm8
November 12, 2010, 4:57am
1
Hi guys,
I need to insert @test.com after each entry in my .txt file.
1
2
3
4
1@test.com
2@test.com
3@test.com
4@test.com
Tried to use
cat test.txt |sed 's/$/@test.com/'
but it does this instead:
1
@test.com
2
@test.com
3
@test.com
4
@test.com
Am i doing something wrong?
ctsgnb
November 12, 2010, 5:49am
2
mv test.txt test.tmp
sed 's/.*/&@test.com/' test.tmp >test.txt
rm test.tmp
spirm8
November 12, 2010, 5:53am
3
Still same problem.
doing a
vi test.txt
revealed ^M after each entry, and that explains it. I removed the ^M by doing a
:%s/^M//g
Thanks for the input
@spirm8 , your sed statement is correct and it should not be doing that. There probably is something wrong with the input file. What platform are you on, how did you create the input file.
Also, what is the output of
od -c < file.txt
and:
printf "1\n2\n3\n4\n" | sed 's/$/@test.com/'
1 Like
ctsgnb
November 12, 2010, 5:56am
5
vi test.txt
:%s/.*/&@test.com/
when in vi in command mode, use
:set list
to enable the display of invisible caracter
:set nolist
to disable the display of invisible caracter
1 Like
spirm8
November 12, 2010, 6:32am
6
Thanks, problem is solved - I removed the ^M in vi using:
:%s/^M//g
and now sed is printing the desired
Thanks for answers
ctsgnb
November 12, 2010, 6:38am
7
Just for your information, this can also be done using the dos2unix
command
1 Like