little challenge for you lunch hour

Okay I have a text file of the format



Multi lined all in this format and what I want to do is strip this out and output it to a file that converts it into

update table set param = ‘parameter2’ where attribute = parameter1;

It’s basically to create an sql script which I can then run into a database.

Who’s man enough for the challenge

'cos I sure as hell ain’t

cat <file> | while read line 
      P_1=`echo $line | cut -f1 -d"|"`
      P_2=`echo $line | cut -f2 -d"|"`
      echo "update table set param = '$P_2' where attribute = $P_1; " >> the_sql.out

That should do it.

:lol: That would be a nice exercise for someone to do in VB :lol:

/me looks round office… :sneaky:
a bit too busy to do if for you over lunch as I need to get to the bank and then going to get haircut for the wedding I’m going to (I’m BestMan :woot: )

If it could wait so I could do it at my leisure over the weekend, then mail it over :slight_smile:


thanks doodz :slight_smile:

Yeah it would only take about 100 lines of VB! :chuckle:

My boss wanted me to write a java app to do it :eek: :scared: :eek: but I resisted but I had to offer an alternative quickly. When will these people learn java is just too big and cumbersome for small stuff such as this :sigh:

oof fixed the code section, noticed I missed the $ on the echo output! :wink:

I was bored so I wrote it on PHP. :slight_smile:

$in_file = 'in.txt';
$out_file = 'out.txt';

$fp_in = file($in_file);
$fp_out = fopen($out_file, 'w');
foreach ($fp_in as $line_in) {
    $tmp = explode('|', trim($line_in));
    $line_out = "UPDATE table SET param = '{$tmp[1]}' WHERE attrib = '{$tmp[0]}';
    fwrite($fp_out, $line_out);

seems Friday afternoon (UK) is the right time to ask for things then. You on a wind down for the weekend Mincer ??

I wish, 2hours office time left, about 6hours work left to do. Ah well, another project bites the dust :rolleyes:


/unless we have a volunteer to do an image standardisation tool ??? all images need to be same aspect ratio, regardless of whether the monkies use the digi camera in portrait or landscape. oh the good bit, got to be done using canvas size based on bigger x or y and has to be in vb. Yeah yeah I know, easy peasy using php… :sigh:

anything you can do with irfanview’s batch processing? unless I’ve got the wrong end of someone else’s stick (no mincer :stuck_out_tongue: )

I might have a look at the irfanview thingy, but at the moment, I have a dodgy way of doing it but it works :lol:

Well works as in well enough to show the boss that I have been working today. But noe 17:30 is here and its time to go home :nod:


Python is rather powerful as well :wink:

for line in open('textfile.txt').readlines():
    print "UPDATE table SET param='" + line.strip("
").split("|")[1] + "' WHERE attribute='" + line.strip("
").split("|")[0] + "'"


EDIT: And don’t get me started about how much more effort this would be in Java :stuck_out_tongue:

Or even trusty old perl :wink:

perl -lpi.bak -e "s/^(.+?)\|(.+)/update table set param = '\$2' where attribute = \$1;/o" test.txt