How to search for a string from/after certain line in text file using bash script?
E.g. I want to search for first occurrence of "version:" string but not at start of file but at line no. say 35 which contains text *-disk:0 so that I would get product name of disk-0 only and nothing else. My current approach is as follows where line_no was line no. of the line where disk:0 is present. But sometimes there is vendor name also present in-between the disk:0 and version. At that time, this logic fails.
ver_line_no=$(echo $(( line_no + 6 ))) ver_line_text=`sed -n ${ver_line_no}p $1` check_if_present=`echo $fver_line_text | grep "version:"` Background: I am trying to parse output of lshw commmand.
*-disk:0 description: ATA Disk product: SAMSUNG physical id: 0 bus info: scsi@z:y:z:0 logical name: /dev/sda version: abc serial: pqr size: 2048GiB capabilities: axy, pqr configuration: pqr, abc, ghj *-disk:1 description: ATA Disk product: TOSHIBA physical id: 0 bus info: scsi@p:q:z:0 logical name: /dev/sdb version: nmh serial: pqasd size: 2048GiB capabilities: axy, pqr configuration: pqr, abc, ghj This is the sample information. I want to print information in tabular format using bash script.