how to extract a particular string in a file using shellscript?

With awk:

 awk '{ match($0,/[0-9]{8}/);arr[substr($o,RSTART,RLENGTH)]+=1;match($0,/blade/);spoint=RSTART+RLENGTH;match($0,/\.demandware/); print substr($0,spoint,RSTART-spoint+1) } END { for (i in arr) { print i" - "arr[i]} } ' file

First check each line for a pattern match of date (8 numbers) create an array arr with the date as the index and increment the value. Then extract matches for blade and demand, using RSTART and RLENGTH to find the string in between. Print this string using substr. In the END block, we print the count of the matches stored in arr.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top