Why don't you simplify your code? It's looking too complex to understand really.
for myfile in `find . -name "R*VER" -mtime +1`
do
echo "Processing $myfile"
# did you mean to use -l instead of -H by any chance?
# Two conditions on RHS and LHS do not produce similar output.
somestr=`grep -H ^err $myfile || echo "$myfile:No error"`
echo " somestr=$somestr"
echo $somestr | awk -F~ '{print $1"\t"$2"\t"$7"\t"$8"\t"$9"\t"$10}
done
Usually I recommend to make it work first using simpler syntax, before you try to make it look more nerdy by putting it all on one single line to impress others. :)
Using the tilde (~) symbol as delimiter in the file name, can I extract the fields I want so I get an output like this
Yes. I do not see any restrictions on which char can and can't be used as delim.
I'd like to do this is one pass so I can generate a SQL script with INSERT statements...Can it be done?
Yes, you're already on the correct path. You just need to adjust print statement inside the awk once you get it to work.
thekashyap
Practically a Posting Shark
811 posts since Feb 2007
Reputation Points: 254
Solved Threads: 75
Skill Endorsements: 0
Each file is parsed only once. So I didn't quite understand what you mean by 2 passes? If you mean two statements inside the loop instead of one, then they can be combined by removing the temp variable somestr .
>> To generate the SQL:
As I said "You just need to adjust print statement inside the awk once you get it to work."
I.e. the awk on line 8 in my script.
Post your code along with a couple of example input files if you need further help.
thekashyap
Practically a Posting Shark
811 posts since Feb 2007
Reputation Points: 254
Solved Threads: 75
Skill Endorsements: 0
Question Answered as of 1 Year Ago by
thekashyap