Extract certain data from two files and put these together in one file - unix command -


i have directory "dir_ling" list of files:

file_i.cnf file_i.cnf.out 

for 0 < < n.

an example of file_i.cnf is

p cnf 8308 33032 c clauses-vars: 3.975927 1 -2 -3 0 -1 2 0 -1 3 0 4 -5 -3 0 

an example of file_i.cnf.out is

[7.03] thread-stats node:0/1 thread:0/1 props:10733141 decs:23093 confs:22488 mem:3.03 [7.03] node-stats node:0/1 solved:1 res:10 props:10733141 decs:23093 confs:22488 mem:3.03 shared:0 filtered:0 [7.03] glob-stats nodes:1 threads:1 solved:1 res:10 rounds:8 time:7.00 mem:3.03 mb props:1533080.49 decs:3298.52 confs:3212.10 shared:0.00 imported:0.00 filtered:0.00 dropped:0.00 

i need command input "dir_ling" , output file dir_ling.timescv each line of file contains name of file "time:" of file *.out , "clauses-vars:" of file *.cnf; example dir_ling.timescv contain

 file_1.cnf 7.00 3.975927  file_2.cnf 8.00 4.909000  .  .  . 

i trying command

 grep "glob-stats" $1/* | grep "solved:1" | tr : " " | cut -d " " -f 1,15 | sed 's/.*\///' | sed 's/\.out//' > solved-$1.times 

with command get

 file_1.cnf 7.00  file_2.cnf 8.00 

my question how can put "clauses-vars:" field?

pipes may not easiest way that. assuming variable $nb contains index number of file, can print 1 line with:

echo file_$nb.cnf \     $(sed -n '/glob-stats/s/.*time:\([.0-9]*\).*/\1/p' file_$nb.cnf.out) \     $(sed -n 's/.*clauses-vars: //p' file_$nb.cnf) 

then can put in loop have $nb loop on indices, , redirect output file.

for details:

  • -n option sed means “do not print output unless explicitely asked”.
  • the first sed command search first file (.cnf.out) line containing glob-stats , performs substitution on it, memorizing digits after time: , replacing whole line it. prints (p) result of substitution.
  • the second sed command erases beginning of line containing clauses-var: in second file , prints (p) result.
  • both sed commands used command substitution (enclosed within $()), commands replaced output on final echo command.

something similar obtained paste and process substitution (paste <(echo $filename) <(sed …) <(sed …))


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -