The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sed string manipulation speedieB Shell Programming and Scripting 4 1 Week Ago 05:27 PM
String Manipulation Help shadow0001 Shell Programming and Scripting 4 03-09-2008 01:35 PM
string manipulation Cactus Jack Shell Programming and Scripting 9 02-14-2008 10:14 AM
string manipulation hai1973 Shell Programming and Scripting 13 08-20-2007 08:27 AM
awk string manipulation zoo591 Shell Programming and Scripting 2 08-09-2006 09:13 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-03-2008
Registered User
 

Join Date: Mar 2008
Posts: 4
string manipulation

Hi,

I have a file with rows of text like so :

E100005568374098100000015667
D100005568374032000000112682
H100005228374060800000002430


I need to grab just the last digits(bolded) of each line without the proceeding text/numbers.

Thanks
Reply With Quote
Forum Sponsor
  #2  
Old 06-03-2008
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
Code:
echo 'E100005568374098100000015667' | sed 's/.*\(.....\)/\1/'
Reply With Quote
  #3  
Old 06-03-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,328
To grab a value in a record without field seperators you have to know the positions of each field IMHO.
You can arbitrary begin at one of the position with a zero but you're never shure you have the right value.

Regards
Reply With Quote
  #4  
Old 06-03-2008
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
actually now that I think about it - I don't know what's common among the values you return.
Is it preceeded with more than one '0'?
Code:
echo 'E100005568374098100000056607' | sed 's/.*00\(.*\)/\1/'
Reply With Quote
  #5  
Old 06-03-2008
Moderator
 

Join Date: Sep 2007
Location: Germany
Posts: 1,031
@vgersh99
You always cut the last 5 characters, no matter if he needs 4 or 6 like in the other rows.

@Franklin52
Yep, that's true. You have to know the possibilties of your file-to-be-parsed very well to limit the chances of unwanted behaviour.

So for the input presented we can say that when at least 5 zeros are in a row, that we can use them to separate the last digits we want:
Code:
sed 's/.*00000\([^0]*\)/\1/'
This will at least make sure, that even if you have 1 up to 4 zero in your last digits, the will be separated ie. parsed correctly. If you have at the end a "600000", you have a problem again. For this I don't have a good solution, as I just thought, that there at least a number of zeros following each other before the last digits come, you want.
If you know that the last digits are always not more than 6 digits, you can parse them like vgersh99 did, ie. add a dot or write it another way and after that cut off all leading zeros.


EDIT: @vgersh99
Oh you saw it already while I was writing
Reply With Quote
  #6  
Old 06-03-2008
Registered User
 

Join Date: Mar 2008
Posts: 4
Thanks everybody, learnt a lot from this. The last piece of code posted has done the trick.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:53 PM.


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

Content Relevant URLs by vBSEO 3.2.0