Removing whitespaces from a line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing whitespaces from a line
# 1  
Old 05-15-2013
Removing whitespaces from a line

HI
I want to remove white spaces from a line
I have a file like
Code:
# cat /clsep
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

I need the output like
0
1
2
3
4
.
.
.
15

I feel sed command cannot be used..
I went through the man page of awk command and found
Code:
cat /clsep | awk '{ print NF}'

It prints the number of columns but am unable to proceed after this..
Please teach/suggest a way to implement my requirement..
# 2  
Old 05-15-2013
Code:
[root@host user]# sed 's/ /\
/g' file

Code:
cat file | tr ' ' '\n'

# 3  
Old 05-15-2013
perl

Hey!!!

Try this out,

Code:
perl -ne '$_ =~ s/\s/\n/go;print $_;' input_file

Cheers!!!
-R
# 4  
Old 05-15-2013
Code:
awk '{$1=$1}1' OFS="\n" /clsep

OFS="\n" Set the output filed separator to new line, instead of space (default).
{$1=$1} Reconstruct the data, so that it uses the new OFS
1 the pattern one is always true, and since no action is specified, do the default, print.

PS No need to cat the file to awk, when awk can read it itself.

Last edited by Jotne; 05-15-2013 at 04:46 AM..
# 5  
Old 05-15-2013
funny one Smilie

Code:
 
printf "%s\n" $(cat filename)

# 6  
Old 05-15-2013
Code:
tr ' ' '\n' < file

Code:
awk '{print $1}' RS=" " file

This User Gave Thanks to MadeInGermany For This Post:
# 7  
Old 05-15-2013
I second balajesuri's and MadeInGermany's tr suggestion.

Unless there's more to your data than a simple space delimiter, all of the awk, sed, and perl suggestions are unwarranted.

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing first and last character of line

Hi all, Please help me to remove first and last character of each line in a file. Thanks, Baski (5 Replies)
Discussion started by: baskivs
5 Replies

2. Shell Programming and Scripting

Removing a line IF the next line contains string

So, I've been working on a project which takes layer 7 metadata from pcap dumps and archives it. However, there is a lot of dataless information that I don't want in my output. I know of ways to produce the output I want from the input file below, but I want a method of doing this, regardless of... (2 Replies)
Discussion started by: eh3civic
2 Replies

3. Shell Programming and Scripting

Help with removing line from text

Hey everyone, I kinda new to shell programming and learning bits and pieces of stuff from tutorials. I got this problem, where I asked my user to enter a string, which will delete a specific line in the string, which I'm unable to do it. Text file(BookDB.txt) as shown: Three Little... (4 Replies)
Discussion started by: aLHaNz
4 Replies

4. Shell Programming and Scripting

Removing same line from a file

Hello , I got a text file like that with many same line main/a/antlr/ main/a/apache2/ main/a/app-install-data-ubuntu/ main/a/apparmor/ main/a/apport/ main/a/apport/ main/a/apport/ main/a/apport/ main/a/apr-util/ main/a/apr-util/ main/a/apt/ main/a/apt/ main/a/apturl/the output... (1 Reply)
Discussion started by: davidkhan
1 Replies

5. Shell Programming and Scripting

Removing spaces in a line

Hi All, I have a line like this " field1;field2;field3 " (single space after and before double quotes). Now i have to remove these single space . Kindly help me. Thanks in advance (2 Replies)
Discussion started by: krishna_gnv
2 Replies

6. Shell Programming and Scripting

Removing last line from file

Hi, I searched the forums but could not find anything that was very useful. I am trying to remove the very last line from a file and display the rest of the file. Is there a way to use cut and tail together? Any other suggestions? Thanks (8 Replies)
Discussion started by: akeenabawa
8 Replies

7. Shell Programming and Scripting

removing new line character

I'm appending header and trailer record for a binary file using echo "$header" > filename cat oldfilename >> filename echo "$trailer" >> filename The echo is introducing newline character after header and trailer.Please let me know is there any possibility to get rid of newline character. (2 Replies)
Discussion started by: ammu
2 Replies

8. UNIX for Dummies Questions & Answers

removing line and duplicate line

Hi, I have 3 lines in a text file that is similar to this (as a result of a diff between 2 files): 35,36d34 < DATA.EVENT.EVENT_ID.s = "3661208" < DATA.EVENT.EVENT_ID.s = "3661208" I am trying to get it down to just this: DATA.EVENT.EVENT_ID.s = "3661208" How can I do this?... (11 Replies)
Discussion started by: ocelot
11 Replies

9. Shell Programming and Scripting

Removing first line from output

my script gives 10 outputs continuously..In each output i have to remove the first line in the output.How to do that. for eg : below is my output 0.00 1.00 5.00 0.00 7.00 i have to remove the first line of this output ie;0.00 (3 Replies)
Discussion started by: Krrishv
3 Replies

10. UNIX for Dummies Questions & Answers

removing last field of the line

I have a text file containing /database/sp/NTR_Vlr_Upload.sql /database/tables/StatsTables.sql /mib/ntr.mib /mib/ntr.v2.mib /scripts/operations/ntr/IMSITracer.ph i want the last field after "/" removed like /database/sp/ /database/tables/ /mib/ /mib/ ... (4 Replies)
Discussion started by: adddy
4 Replies
Login or Register to Ask a Question