The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Of bash and whitespace... lev_lafayette Shell Programming and Scripting 2 04-13-2008 05:44 PM
Delete whitespace truck7758 Shell Programming and Scripting 12 12-05-2007 08:00 AM
sed : remove whitespace b.hamilton Shell Programming and Scripting 3 11-06-2007 07:02 AM
trim whitespace? msteudel Shell Programming and Scripting 4 07-07-2005 04:57 PM
remove whitespace and test bensky Shell Programming and Scripting 4 09-25-2003 05:02 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-03-2008
Registered User
 

Join Date: Jun 2008
Posts: 16
Stumble this Post!
sed and whitespace characters

I have teh follwing details in a file:

SmithA..... ,,400
JonesA..... ,,300
JamesA..... ,,600
BakerA ,,800
ChrisA ,,1200


the first field name is 6 characters in length always and alays ends with an 'A'.
The periods denote white space (space caharacters), as you can see on certain occurences ther are many 'spaces' and in other instances no 'spaces'.

I want to be able to make the above file as below:

SmithA. ,,400
JonesA. ,,300
JamesA. ,,600
BakerA. ,,800
ChrisA. ,,1200


So anly one single whitespace is present after the las 'A' character.
I have treied the following,

sed 's/ *//g' fileA > fileB
which gives me:

SmithA ,,400
JonesA ,,300
JamesA ,,600
BakerA ,,800
ChrisA ,,1200

however i am now not so sure how to put a whitecase character back in after the A to get the format as required above.
Could anyone assist, also would perferably be ideal if i could have the whole thing processed in one single sed command.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 07-03-2008
Moderator
 

Join Date: Feb 2007
Posts: 1,961
Stumble this Post!
Try this:

Code:
sed 's/\(......\).*\(,,.*\)/\1 \2/' fileA > fileB
Regards
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:56 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0