6.5.2014

Cut config to pieces using awk and test each piece separately

Filed under: bash,scripting,Uncategorized — nax @ 13:17

Not user friendly tools are horrible. It is usually consequence of not “eat your own dog food”. If the programmer doesn’t need to use the tool, then it is not very usable. Then you have to use some workaround.

For instance just now. I have config file enumerating multiple files to load:


//some header
key1=value
key2= value
// file1
load=file_484
load.params=some params
load.subfile=file_696
// file2
load=file_837
load.params=some params
load.subfile=file_694
...
// file58
load=file_5928
load.params=some params
load.subfile=file_3847

Now when I run the tool, I get error that file is not compatible. But how to find out which file out of 58? One way would be to use strace tool to see which file it tries to open just before the error message. Unfortunately not an option in this case.

So I used this trick:
1) cut config to 58 pieces
2) run tool with each config contain just one input file config

First I used awk to cut original file to pieces. In vim I deleted “file<>” using command :%s/^\/\/.*$/\/\// and then I used 2 slash as a record separator:

awk -v RS="//" 'BEGIN{i=10}{print $0 > "piece"i;i++}' input.txt

Then I run following bash cycle to iterate thru all the configs:

for f in piece*; do cat header.txt $f > script_input.conf; sh ./script.sh script_input.conf; done

Comments are closed.

Powered by WordPress