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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to monitor remote shell execution on linux 9 113
Oracle Finace 3 104
retrieve nuemaric value from txt file in shell script 3 89
umask commands 5 22
When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
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 several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…
Suggested Courses

710 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