I need to parse a word: awk or sed?
I just need a one-liner. I search this directory for a file named finished.[then a number] "finished.3". It will never go over 9. I just want to grab the number from the end of the file name to put it in an if statement.
$(ls /dir/number.* | %%%%% ) I'm thinking either awk or sed, but I've never run across anything that parses words. It can be based on the the characters of the line too... Thoughts? |
Grepping the number-part from a string (3 if finished.3)
Using sed: ls finished.[0-9] | sed 's/finished\.\([0-9]\)/\1/' Using awk: ls finished.[0-9] | awk -F"." '{ print $2 }' There are probably many more ways to do this. Hope this helps. |
You can also use cut:
Code:
ls finished.[0-9] | rev | cut -c1 Code:
for FILE in `ls finished.[0-9]` ; do echo ${FILE##*\.} ; done |
Quote:
bruce |
Thanks a lot guys.
I ended up going with awk and changing the field separator. $(ls /vmware/number.* | awk 'BEGIN { FS = "." } ; { print $2 }' ) |
Spectacular? What?! ;):D shell-jutsu, but still not at dan grade :p:)
|
All times are GMT -5. The time now is 06:53 PM. |