Solved

remove new line char

Posted on 2011-09-20
4
223 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
  • 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 500 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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

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…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

773 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