extracting part of a string (sed, bash, ...)
I have a sample string like below (with same formatting but length of the fields and integers may vary):
AtmIf/62 Vpt/3 Uni Addr/39206510001234567890,primary I need to extract the 39206510001234567890 (length may vary) I would like to do that using sed and Regular expressions but I can't get it right. If sed won't do it i would like to use a bash script, awk, etc. I know how to do it in Perl but this is not possible in this case. Thanks in advance for your help. |
Hi,
Using sed: sed 's%.*/\(.*\),.*%\1%' infile or echo "AtmIf/62 Vpt/3 Uni Addr/39206510001234567890,primary" | sed 's%.*/\(.*\),.*%\1%' Hope this helps. |
This helps indeed.
Thank you druuna. |
If the string is always longer than 2 numbers, then the regex is simple. Using GREP, this works:
(Assumes the desired string is always at least 5 numbers---"num" is the file I generated to hold your example) Code:
grep -o '[0-9]\{5,\}' num This can also be done with SED, but probably will be messier |
All times are GMT -5. The time now is 03:09 PM. |