Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

My file name is Oracle.2347263_testing_152607.csv I tried this :

echo Oracle.2347263_testing_152607.csv | sed -e 's/.*G.//'   \-e 's/.csv//'

but I didn't get the result I expected.

I want to extract 2347263 from Oracle.2347263_testing_152607.csv please help

share|improve this question
3  
awk -F'[._]' '{print $2}' –  jasonwryan Feb 2 at 23:43
    
grep -o "\b[0-9]\+" –  Costas Feb 3 at 0:13
1  
If you're using bash and the filename is already in a variable, this is cheaper: i=Oracle.2347263_testing_152607.csv and then j=${i#Oracle.*} ; echo ${j%%_*}. –  ott-- Feb 3 at 23:06

2 Answers 2

up vote 1 down vote accepted
$ echo Oracle.2347263_testing_152607.csv | sed -e 's/Oracle.\([[:digit:]]*\)_.*/\1/'
2347263
share|improve this answer
    
Thanks for the response. I tried this but got some error sed: illegal option -- r Usage: sed [-n] [-u] Script [File ...] sed [-n] [-u] [-e Script] ... [-f Script_file] ... [File ...] –  ora_unix Feb 2 at 23:46
    
"got some error" What error? It works fine for me. If it doesn't work for you, show me exactly what happened. –  John1024 Feb 2 at 23:46
    
sed: illegal option -- r Usage: sed [-n] [-u] Script [File ...] sed [-n] [-u] [-e Script] ... [-f Script_file] ... [File ...] –  ora_unix Feb 2 at 23:48
    
@ora_unix OK. That error looks like you are using a BSD sed. Answer updated. –  John1024 Feb 2 at 23:56
    
That worked.. Thanks lot John –  ora_unix Feb 3 at 0:00

Try the following:

$ echo Oracle.2347263_testing_152607.csv |cut -f 2 -d "." |cut -f 1 -d "_"
2347263
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.