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
Add white space to the end of a line with sed karlanderson Shell Programming and Scripting 7 03-09-2009 06:20 AM
How to trim the white space around a string in C program hxm1303 High Level Programming 18 10-17-2008 10:43 AM
wc of characters in a file ignoring white space sachin.gangadha UNIX for Dummies Questions & Answers 1 12-15-2007 06:13 PM
How to get just the word and clean the white space? paulofp Shell Programming and Scripting 2 06-22-2007 06:28 PM
How to keep white space is being deleted using read keelba Shell Programming and Scripting 1 05-30-2002 02:15 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-05-2007
Zak Zak is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 31
stripping white space...

Hi All;

Having a problem with a file..

the file contains the following data... (a snapshot)

1331F9E9DB7C2BB80EAEDE3A8F043B94,AL7 1DZ,M,50
186FDF93E1303DBA217279EC3671EA91,NG5 1JU,M,24
3783FFAF602015056A8CD21104B1AAAF,CH42 4NQ,M,17

It has 3 columns sepreated by a ,
the second column as a space in the middle of it..

1331F9E9DB7C2BB80EAEDE3A8F043B94,AL7 1DZ,M,50
I want to run a script against the file to strip that white space. Not really where to start.

Any pointers will greatly appericated

Thanks
  #2 (permalink)  
Old 10-05-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,518
Code:
awk 'BEGIN{OFS=FS=","}{ gsub(" ","",$2) }1' "file"
  #3 (permalink)  
Old 10-05-2007
Zak Zak is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 31
Hi

Thanks very much for the prompt reply.. I tried running the command you gave me on command line I'm getting a few errors

> awk 'BEGIN{OFS=FS=","}{ gsub(" ","",$2) }1' "user.db"
awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: bailing out near line 1
>

I'm running on solaris 9.
  #4 (permalink)  
Old 10-05-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
As always...... use 'nawk' instead of plain old 'awk' on Solaris...
  #5 (permalink)  
Old 10-05-2007
Zak Zak is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 31
Gentlemen,

I'm humbled by your knowledge
  #6 (permalink)  
Old 10-09-2007
aajan aajan is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 80
U can Try this also!!!!!!!!!!!!!!!!!!!!!!!!!


cat filename | tr -s ' ' ','

Regards,
aajan
  #7 (permalink)  
Old 10-09-2007
manas_ranjan's Avatar
manas_ranjan manas_ranjan is offline
Registered User
  
 

Join Date: Jul 2007
Location: Amsterdam
Posts: 177
hey i have taken one line of your test file as follows,
var1="1331F9E9DB7C2BB80EAEDE3A8F043B94,AL7 1DZ,M,50"
then
echo $var1 | tr -d " "
o/p:1331F9E9DB7C2BB80EAEDE3A8F043B94,AL71DZ,M,50

surely it might help you out, if a blank space/tab is there .
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 09:28 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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