LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   AIX (https://www.linuxquestions.org/questions/aix-43/)
-   -   sed on AIX and HP-UX (https://www.linuxquestions.org/questions/aix-43/sed-on-aix-and-hp-ux-4175506995/)

fritz001 06-04-2014 04:35 AM

sed on AIX and HP-UX
 
Hello all,

I'm facing this issue in my attempt to use sed to extract a variable number from a string

I do have something like this:

file_fruxt0000006_5300-12_20140601152
file_fruxt0000036_6100-12_20140601


I'd like to extract the last number from the string

colucix 06-04-2014 05:01 AM

Does
Code:

echo file_fruxt0000006_5300-12_20140601152 | sed 's/.*_//'
give the desired result?

fritz001 06-04-2014 05:10 AM

Quote:

Originally Posted by colucix (Post 5182103)
Does
Code:

echo file_fruxt0000006_5300-12_20140601152 | sed 's/.*_//'
give the desired result?

Yes, thanks

meantime I realized I can use awk -F_ '{print $NF}'

NevemTeve 06-05-2014 04:07 AM

Or just:
Code:

X='file_fruxt0000006_5300-12_20140601152'; echo "${X##*_}"


All times are GMT -5. The time now is 04:32 PM.