How to translate multiple spaces into a single space using tr command?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to translate multiple spaces into a single space using tr command?
# 1  
Old 09-28-2011
How to translate multiple spaces into a single space using tr command?

I am trying to read a txt file and trying to translate multiples spaces into single spaces so the file is more organized, but whenever I try the command:

Code:
tr ' ' '    ' w.txt

The output is:

Code:
tr: extra operand `w.txt'
Try `tr --help' for more information.

Can someone please help? Smilie

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.
# 2  
Old 09-28-2011
Code:
tr -s \ <infile

# 3  
Old 09-28-2011
I totally forgot about redirection!

Thank you!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replacing Multiple spaces with a single space but excluding few regular expressions

Hi All. Attached are two files. I ran a query and have the output as in the file with name "FILEWITHFOURRECORDS.txt " I didn't want all the spaces between the columns so I squeezed the spaces with the "tr" command and also added a carriage return at the end of every line. But in two... (3 Replies)
Discussion started by: sparks
3 Replies

2. Shell Programming and Scripting

awk - CSV file - field with single or multiple spaces

Hi, In a csv file, I want to select records where first column has zero or multiple spaces. Eg: abc.csv ,123,a ,22,b ,11,c a,11,d So output should be: ,123,a ,22,b ,11,c Please advise (5 Replies)
Discussion started by: vegasluxor
5 Replies

3. UNIX for Dummies Questions & Answers

Replacing double spaces with single space

I am looking for a regular expression that uses sed to replace multiple spaces with single spaces on every line where it is not at the start of the line and not immediately before double slashes ('//') or between quotes ("). In its simplest form, it would look like this: sed -e 's# # #g'... (4 Replies)
Discussion started by: figaro
4 Replies

4. Shell Programming and Scripting

Transpose multiple rows (with a mix of space and enter) to a single column

How to change the uploaded weekly file data to the following format? New Well_Id,Old Well_Id,District,Thana,Date,Data,R.L,WellType,Lati.,Longi. BAG001,PT006,BARGUNA,AMTALI,1/2/1978,1.81,2.29,Piezometer,220825,901430 BAG001,PT006,BARGUNA,AMTALI,1/9/1978,1.87,2.29,Piezometer,220825,901430... (3 Replies)
Discussion started by: sara.nowreen
3 Replies

5. UNIX for Dummies Questions & Answers

[SOLVED] splitting a single column(with spaces) into multiple rows

Hi All, My requisite is to split a single column of phonemes seperated by spaces into multiple rows. my input file is: a dh u th a qn ch A v U r k my o/p should be like: adhu a dh u (3 Replies)
Discussion started by: girlofgenuine
3 Replies

6. Shell Programming and Scripting

How to avoid the truncating of multiple spaces into a single space while reading a line from a file?

consider the small piece of code while read line do echo $line done < example content of example file sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr the output is like sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr the... (4 Replies)
Discussion started by: Kesavan
4 Replies

7. Shell Programming and Scripting

Cannot get to convert multiple spaces to one space

Hi Guys, I am using a Redhat Linux Centos machine and trying to convert multiple spaces in a file to one space. I am using: sed '/./,/^$/!d' input_file > output_file I also tried cat -s Both gave me no change in the output file. I tried this on cygwin and it worked... (7 Replies)
Discussion started by: npatwardhan
7 Replies

8. Shell Programming and Scripting

can v add 'n' of spaces by a single command?

Hi All, I just need to check for 'tabs' in my input file and need to replace all tabs into 'n' no. of spaces. Say for example if I give NO_OF_SPACE=5, then it should replace all tabs with 5 spaces abc.in ##### asdasdasd \t\t\tasjkalskdl;asdsdjfksldfjklsdfxcmxm,cv... (2 Replies)
Discussion started by: askumarece
2 Replies

9. Shell Programming and Scripting

replace space or spaces in a line of a file with a single :

I am searching while I await a response to this so if it has been asked already I apologize. I have a file with lines in it that look like: bob johnson email@email.org I need it to look like: bob:johnson:email@email.org I am trying to use sed like this: sed -e 's/ /:/g' file >... (5 Replies)
Discussion started by: NewSolarisAdmin
5 Replies

10. Shell Programming and Scripting

Consecutive spaces within input being converted to single space

I'm reading from a file that is semi-colon delimited. One of the fields contains 2 spaces separating the first and last name (4th field in - "JOHN<space><space> DOE"): e.g. TORONTO;ONTARIO;1 YONGE STREET;JOHN DOE;CANADA When I read this record and either echo/print to screen or write to... (4 Replies)
Discussion started by: NinersFan
4 Replies
Login or Register to Ask a Question