1

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

  • 4
    awk -F'[._]' '{print $2}' – jasonwryan Feb 2 '15 at 23:43
  • grep -o "\b[0-9]\+" – Costas Feb 3 '15 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 '15 at 23:06
1
$ echo Oracle.2347263_testing_152607.csv | sed -e 's/Oracle.\([[:digit:]]*\)_.*/\1/'
2347263
  • 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 '15 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 '15 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 '15 at 23:48
  • @ora_unix OK. That error looks like you are using a BSD sed. Answer updated. – John1024 Feb 2 '15 at 23:56
0

Try the following:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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