The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Removing spaces... lost UNIX for Dummies Questions & Answers 2 10-06-2008 05:46 PM
removing spaces sahithi_khushi Shell Programming and Scripting 2 11-03-2006 11:20 AM
Removing spaces at particular position superprogrammer Shell Programming and Scripting 7 07-10-2006 05:29 AM
removing spaces after sperator vishnu_vaka Shell Programming and Scripting 6 03-24-2006 10:17 AM
Removing spaces between records thanuman UNIX for Dummies Questions & Answers 6 11-17-2005 01:01 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-18-2009
ippy98 ippy98 is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 8
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

Last edited by ippy98; 03-18-2009 at 06:46 AM.. Reason: found answer
  #2 (permalink)  
Old 03-18-2009
Whiteboard's Avatar
Whiteboard Whiteboard is offline
Registered User
  
 

Join Date: Feb 2009
Location: @........
Posts: 111
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 07:00 AM..
  #3 (permalink)  
Old 03-18-2009
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
You can do something like this--

Code:
echo "01 3F 20 1F" | tr -d " "
  #4 (permalink)  
Old 03-18-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,422
Code:
# a="01 3F 20 1F"
# echo ${a// /}
013F201F
  #5 (permalink)  
Old 03-18-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,382
Smile

just another way
Code:
echo "A B C E"|awk '/ /{gsub(" ","")}1'
  #6 (permalink)  
Old 03-18-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,422
Quote:
Originally Posted by vidyadhar85 View Post
just another way
Code:
echo "A B C E"|awk '/ /{gsub(" ","")}1'
Code:
# echo "A B C E"| awk '$1=$1' OFS=""
ABCE
  #7 (permalink)  
Old 03-18-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,382
Quote:
Originally Posted by ghostdog74 View Post
Code:
# echo "A B C E"| awk '$1=$1' OFS=""
ABCE
this won't work for the below case
Code:
 
fnsonlu1-/home/fnsonlu1> echo "A   VB        CV"| awk '$1=$1' OFS=""
A   VB        CV
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 05:03 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0