0

Possible Duplicate:
SED: How can I replace a newline (\n)?

I have the file with newlines. and I am trying this

sed -re 's/\n//' sample1.txt and it's not working

It's showing output with newlines and not removing them.

Community
  • 1
  • 1
user175386049
  • 451
  • 1
  • 6
  • 12

2 Answers2

1

sed splits the input it receives at newlines and removes them before running the sed script, i.e. the script will never see then newlines. Use tr instead:

tr -d '\n'

Or if you insist on sed, use Guru's looped solution which re-inserts \n with the N command.

Thor
  • 45,082
  • 11
  • 119
  • 130
  • Do you have any better solution with sed only. Thanks for `tr` but i just want to know – user175386049 Jan 08 '13 at 06:18
  • @user1953864: No, this is not a job for sed, even with the looped solution you end up with a newline at the end. You should probably come up with a minimal example of what you're trying to do. – Thor Jan 08 '13 at 08:01
-2

Use double quotes:

sed -e "s/\n//" sample1.txt

If your intention is to try and join all lines in a file:

sed -e :a  -e 'N;s/\n//;ta'  sample1.txt
Guru
  • 16,456
  • 2
  • 33
  • 46