Removing spaces from string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing spaces from string
# 1  
Old 03-18-2009
Removing spaces from string

I want a user to be able to paste in a string like "01 3F 20 1F" and have the script reformat it to "013F201F" to pass it on to the next step.

I was trying to figure it out with awk but wasnt working well.


Never mind, found answer. did not know about tr Smilie

Last edited by ippy98; 03-18-2009 at 07:46 AM.. Reason: found answer
# 2  
Old 03-18-2009
use sed..

$ echo "01 3F 20 1F" | sed 's/ //g'
013F201F

found the answer by yourself thats good.....

Last edited by Whiteboard; 03-18-2009 at 08:00 AM..
# 3  
Old 03-18-2009
You can do something like this--

Code:
echo "01 3F 20 1F" | tr -d " "

# 4  
Old 03-18-2009
Code:
# a="01 3F 20 1F"
# echo ${a// /}
013F201F

# 5  
Old 03-18-2009
Bug

just another way Smilie
Code:
echo "A B C E"|awk '/ /{gsub(" ","")}1'

# 6  
Old 03-19-2009
Quote:
Originally Posted by vidyadhar85
just another way Smilie
Code:
echo "A B C E"|awk '/ /{gsub(" ","")}1'

Code:
# echo "A B C E"| awk '$1=$1' OFS=""
ABCE

# 7  
Old 03-19-2009
Quote:
Originally Posted by ghostdog74
Code:
# echo "A B C E"| awk '$1=$1' OFS=""
ABCE

this won't work for the below case Smilie
Code:
 
fnsonlu1-/home/fnsonlu1> echo "A   VB        CV"| awk '$1=$1' OFS=""
A   VB        CV

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk print string with removing all spaces

Hi all, I want to set 10 set of strings into a variable where: removing all spaces within each string change the delimiter from "|" to "," Currently, I've the below script like this:Table=`ten character strings with spaces in-between and each string with delimiter "|" | tr -d ' ' |... (7 Replies)
Discussion started by: o1283c
7 Replies

2. Shell Programming and Scripting

removing spaces in filenames

I have a problem mounting images because of the spaces in the filenames. Does anyone know how to rename files by removing the spaces with the find command? find Desktop/$dir -name "*.dmg" -print -exec ??? (4 Replies)
Discussion started by: ianebaj
4 Replies

3. Shell Programming and Scripting

Removing blank spaces, tab spaces from file

Hello All, I am trying to remove all tabspaces and all blankspaces from my file using sed & awk, but not getting proper code. Please help me out. My file is like this (<b> means one blank space, <t> means one tab space)- $ cat file NARESH<b><b><b>KUMAR<t><t>PRADHAN... (3 Replies)
Discussion started by: NARESH1302
3 Replies

4. Shell Programming and Scripting

Removing spaces from data

Hi, I want to remove spaces from data. Data is: 1,aa ,21, 22 2,a a ,23 ,24 3, ,25 ,26 output should be: 1,aa,21,22 2,a a,23,24 3, ,25,26 i.e i have to remove leading and trailing spaces.Not the space between data and also i dont want to remove the space if data is... (4 Replies)
Discussion started by: monika
4 Replies

5. UNIX for Dummies Questions & Answers

Removing spaces...

Hey, I'm using the command from this thread https://www.unix.com/unix-dummies-questions-answers/590-converting-list-into-line.html to convert vertical lines to horzontal lines. But I need to remove the spaces that is created. Unfortunately I can't figure out where the space is in the code.. I... (2 Replies)
Discussion started by: lost
2 Replies

6. Shell Programming and Scripting

removing spaces

hey.. i had a problem with the unix command when i want to remove the white spaces in a string..i guess i cud do it with a sed command but i get an error when i give space in the square brackets.. string="nh hjh llk" p=`echo $string | sed 's/ //g'` i donno how to give space charater and... (2 Replies)
Discussion started by: sahithi_khushi
2 Replies

7. Shell Programming and Scripting

removing spaces after sperator

Hi friends i have problem 6000000001| CDC049| 109| CDC| 02/02/2006| Auto| New Add| 02/03/2006 6000000002| CDC033| 109| CDC| 02/02/2006| Auto| New Add| 02/03/2006 6000000003| CDC037| 109| CDC| 02/02/2006| Auto| New Add| 02/03/2006 6000000004| CDC031| ... (6 Replies)
Discussion started by: vishnu_vaka
6 Replies

8. UNIX for Dummies Questions & Answers

Removing spaces between records

Hi I have an XML file. Which has spaces between different records.... current file( Has many lines, like this... I want to delete all the spaces between > and <, if there are only spaces between them) input file <xyzr> <abc>1234</xyzr> <aaa> <bbb> ayz mnz</bbb> <sen>KEA... (6 Replies)
Discussion started by: thanuman
6 Replies

9. UNIX for Dummies Questions & Answers

removing spaces from variables?

I stored results like this VAR=`wc -l < ls.txt` But the value of the wc gave me a padded number. How do I strip the padding from $VAR? Do you think I could use SED? Except instead of a file input, have a variable redirection input? (2 Replies)
Discussion started by: yongho
2 Replies

10. Shell Programming and Scripting

removing spaces in a file

I have output a file and need to remove blank spaces in the first lines only so the file is left end justified. I need to do this while keeping the rest of the file intact. Example of file that needs spaces removed: space space space space space space space... (3 Replies)
Discussion started by: tioray
3 Replies
Login or Register to Ask a Question