Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

remove new line char

i have a file with a list of hostnames - each host on a new line. I tried to remove them unsuccessfully with sed. Any help would be greatly appreciated .

sed 's/\n//' <filein >fileout.

I also tried it in vi with %s/Ctrlv backspace//g but that didn't work either
0
lolaferrari
Asked:
lolaferrari
  • 2
  • 2
1 Solution
 
medveddCommented:
If you want to remove all new lines, this command will do:

tr -d '\012' <filein >fileout
0
 
medveddCommented:
You probably need to separate hostnames with spaces, this is better way to do it:

sed -e :a -e N -e 's/\n/ /' -e ta <filein >fileout
0
 
woolmilkporcCommented:
echo $(cat filein) > fileout
0
 
woolmilkporcCommented:
a bit shorter, avoiding "cat", so it's purely using shell builtins:

echo $(<filein) > fileout
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now