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 > 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 11-23-2008 08:27 PM
String Manipulation Help shadow0001 Shell Programming and Scripting 4 03-09-2008 04:35 PM
string manipulation Cactus Jack Shell Programming and Scripting 9 02-14-2008 01:14 PM
string manipulation hai1973 Shell Programming and Scripting 13 08-20-2007 11:27 AM
awk string manipulation zoo591 Shell Programming and Scripting 2 08-09-2006 12:13 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-03-2008
james6 james6 is offline
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
  #2 (permalink)  
Old 06-03-2008
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
echo 'E100005568374098100000015667' | sed 's/.*\(.....\)/\1/'
  #3 (permalink)  
Old 06-03-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
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
  #4 (permalink)  
Old 06-03-2008
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
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/'
  #5 (permalink)  
Old 06-03-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,259
@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
  #6 (permalink)  
Old 06-03-2008
james6 james6 is offline
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.
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 11:37 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