![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Code:
echo 'E100005568374098100000015667' | sed 's/.*\(.....\)/\1/' |
|
#3
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
@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/' 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
|
|||
|
|||
|
Thanks everybody, learnt a lot from this. The last piece of code posted has done the trick.
|
|||
| Google The UNIX and Linux Forums |