bash - An awk script to run over different files -


i have wrote script: looking.awk searches particular data in file:

 {if ($0 ~ "neighbors of non-equivalent atoms") {flag=1}};  # if current line of file begins string, asign flag=1      {if (flag==1)             {if ($0 ~ $1==1 && $2=="ca" && $6==14 && $7=="o"){line=$0;             exit}             }     };     # here searching "1 ca" on each line   end{vol=filename;  # filename is: "c_from_v_273_008245_50_neighbours_symremo.out"  # intention end new file 2 columns:  # "volume" , "distance".   # notice filename contains volume: 273.008245   gsub("^.*_v_","",vol);  gsub("_",".",vol);  gsub(".50.neighbours.symremo.out"," ",vol);  # substitutions make "c_from_v_273_008245_50_neighbours_symremo.out"   # "273.008245"   # output of running:   # search_for_distance.awk -f c_from_v_273_008245_50_neighbours_symremo.out  # following:   # 273.008245     1 ca   1     2.4055     4.5458    7 o    0 0 0   # so, need take line , extract column "4".  # done "split" command:   {split(line,array," ")}      print vol,array[4]} 

the script located in current folder .

i have several folders , files in i'd run script.

these paths:

 .../cvolopts_and_f9_for_labels_v_247_803181/c_v_247_803181_50_neighbours_symremo.out   .../cvolopts_and_f9_for_labels_v_250_532893/c_v_247_803181_50_neighbours_symremo.out   .  .  . 

i running script as:

 awk -f looking.awk ../cvolopts*_v*/calcite_iiib*v*50_n*_symremo.out > ./d_ca-1_o_7/data.dat 

but in data.dat generated there result of script on .../cvolopts_and_f9_for_labels_v_247_803181/c_v_247_803181_50_neighbours_symremo.out file

how can run script looks inside .out files in paths?

thank help

how can run script looks inside .out files in paths?

find /base/directory/to/search -type f -name "*.out" -exec awk -f /path/to/looking.awk {} >>/path/to/d_ca-1_o_7/data.dat \; 

what happening here?

  1. we set /base/directory/to/search base directory search.
  2. we ask find find files type directive.
  3. we wish files ending .out set name *.out. * here wild-card expand possible outputs filter using criteria mentioned in 1 & 2.
  4. -exec used apply commands on filtered output. pipe process output of find. @ same time different normal pipe (|) in formatting applied find -say -print0 - retained exec. formatting done in cases process non-standard files,for example, files new-lines or special characters. use {} pass formatted string command.
  5. we awk stuff , append results dat file.

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -