Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

remove new line char

Posted on 2011-09-20
4
Medium Priority
?
227 Views
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
0
Comment
Question by:lolaferrari
[X]
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
4 Comments
 
LVL 16

Expert Comment

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

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

Expert Comment

by:medvedd
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
0
 
LVL 68

Accepted Solution

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

Expert Comment

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

echo $(<filein) > fileout
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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 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.:
Suggested Courses

715 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