Am 31.05.2012 01:22, schrieb Matthew Kruer:
> What i am trying to accomplish is to build a bash file to run
>
> I have a file that contains a coma delimited fields (package name,
> build number, uarch) Example below package1, 1.1.0.24-0, noarch
> package2, 1.0.0.8-1, noarch etc...
>
> I am trying to read the file and generate a bash script based upon is
> contents First thing i need to do is generate a bash script to change
> the version field in a file. This is the area that I am running into
> issues with because of the quotes and string replacement
> awk -F ',' '{print "sed -i 's/version = '*'/version = '$2'/g' /path/$1 "}' inputfile
A few hints...
If you put the whole awk program into a file, say mycmds.awk, and
call it as
awk -F, -f mycmds.awk inputfile >outputfile
you won't have the issues with the nested single quotes.
Using printf instead of print will result in code that will make it
clearer visible what output you will get.
You can also do both, the initialisation of the matching rules that
you have in inputfile, and the processing of the data files in one
awk run without need of another shell or a couple of individual sed
processes. For example...
awk -F ', ' -f myscript inputfile
where myscript contains
NR==FNR { f="/path/"$1 ; ARGV[ARGC++]=f ; vers[f]=$2 ; next }
{ gsub(/version = '*'/,"version = '"vers[FILENAME]"'") ; print }
The first line will extend the command line by the files to process,
and will set up a mapping table with the version information. The
second line will be processed for each subsequent files and will do
the substitution.
Janis