0

i have 1000 files with filename like this :

total_val_count.html?itemid=5555

with content

total.val={"number":1234,"Validation":YES}

i want output like this itemid:number using awk

5555:1234

Thanks

New contributor
H.Otmane is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • Are you sure that '?' sign is part of your filenames, since it is special to bash shell, or is it excerpt from apache log or something with calls to CGI bin executables? – gmt42 Mar 14 at 21:31
1

If you have GNU Awk:

$ gawk '
  BEGINFILE{
    split(FILENAME,a,/=/)
  } 
  match($0,/"number":[0-9]+/){
    printf "%s:%d\n", a[2], substr($0,9+RSTART,RLENGTH)
  }
  ' total_val*
5555:1234

Or with Perl

$ perl -lnE '$x = (split /=/,$ARGV)[1]; say "$x:$1" if /"number":(\d+)/' total_val*
5555:1234

In neither case is any checking done (for example, that the filename splits successfully on an = sign).

  • Thanks bro !! its working fine – H.Otmane Mar 15 at 12:59

Your Answer

H.Otmane is a new contributor. Be nice, and check out our Code of Conduct.

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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