sed - Find a 4 digit number and get the text after them -


i need extract numbers .sql file name: "tdb_full_335.51_2013_02_14.sql" want "2013_02_14" can with:

echo $(find -s ~/downloads | grep -e '\.sql' | awk -f/ '{print $nf}' | sed -n '/tdb_full/p' | awk 'end{print}' | awk '{gsub(".sql", "");print}' | cut -d "_" -f4 -f5 -f6) 

this ok if filename length changes fail. there way search 4 digits "2013" , digits after ".sql"?

if found this:

grep -o '\([[:digit:]]\)\{4\}' 

but gives me "2013"

you can match 2013 , following 0-9 , _ easily;

grep -o '\(2013[0-9_]*\)' 

using 2013 hard coded may not idea in long run, may want use like;

grep -o '\(2[0-9]\{3\}_[0-9_]*\)' 

...to match 4 digit year starting 2.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -