-3

I know it is simple but not getting it. I have a shell script and inside the script a variable holds value like below - Record 1: [record bdfo_len 73 bdfo_key " 200000014" bdfo_param_no "000" parm01 NULL parm02 NULL parm03 NULL parm04 NULL parm05 NULL parm06 NULL parm07 NULL parm08 NULL parm09 NULL parm13 NULL parm16 NULL parm017 NULL parm18 NULL parm93 NULL parm94 NULL parm96 NULL parm97 NULL parm83 NULL header [record bdfo_run_date 41991 bdfo_file_id "GYFL3027" bdfo_centre_id "G" bdfo_sbi_file_ind "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY"] trailer NULL data NULL] Record 2: [record I need to extract bdfo_run_date out of it, how to get that please?

Vikas
  • 9
  • 3
  • Hi, If any of the following answer helped you then please acknowledge by accepting the answer by ticking the right sign beside the answer. You can also upvote others who are providing multiple approaches to solve the same problem. – P.... Jul 05 '17 at 05:51

2 Answers2

0

If you are using bash with regexp support, you can construct a regexp that matches the part of the input you are interested in:

bdfo_run_date [0-9]+

Put the part you need in parentheses, and use the =~ operator that puts the the match result in the array BASH_REMATCH:

[[ $INPUT =~ bdfo_run_date\ ([0-9]+) ]] && echo "${BASH_REMATCH[1]}"
lovei
  • 250
  • 1
  • 7
0
echo "$recordVariable" |grep -oP 'bdfo_run_date\s+\K[^ ]+' 
41991
P....
  • 17,421
  • 2
  • 32
  • 52