remove new line char

Posted on 2011-09-20
Last Modified: 2012-05-12
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
Question by:lolaferrari
  • 2
  • 2
LVL 16

Expert Comment

ID: 36569353
If you want to remove all new lines, this command will do:

tr -d '\012' <filein >fileout
LVL 16

Expert Comment

ID: 36569430
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
LVL 68

Accepted Solution

woolmilkporc earned 500 total points
ID: 36569454
echo $(cat filein) > fileout
LVL 68

Expert Comment

ID: 36569472
a bit shorter, avoiding "cat", so it's purely using shell builtins:

echo $(<filein) > fileout

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question