Ruchi vs. the flat file
Posted in 1992
RUCHI@CFRVM.CFR.USF.edu writes: > I wrote a shell script with help from this list to add data from ACII file. > This works like a charm. I used the ISQL, LOAD, and INSERT command to do this. > My question is that how would I update or remove the data using the flat file? > In ascii file, first character designates whether I want to remove or update. Thought you would've fixed it by now - if not, try something like the one at the bottom. Note that I've only checked the unix, there may be typos in the SQL. Should give you the idea, tho'. The script writes load.sql, you can call isql on that. Alternatively (= better), pipe the whole lot straight into isql without the tempfile. I don't have an isql, so I didn't :-) Maybe add another echo "database mydb;" at the start. > Please help me if this is possible using shell script and ISQL comands. Believe so :-) > Some suggested that I could write C and do this using 4gl. But the problem > is that I don't know C but if you have sample example, I would really > appreciate. I need to do this right away. > > Thanks alot. > > Ruchi. Hope you get my drift - you'll need different numbers of dots, and you'll have to hack the sed stuff, but it should work. Have fun ! Cheers - Tony. PS. How 'bout some more jobs pages ? __________________________________________________________________________ Tony Heskett th@bnr.co.uk Voice: (+44) 279 429531 x 2637 BNR, London Road, Harlow, Essex, CM17 9NA Fax: (+44) 279 454187 __________________________________________________________________________ : # Demo for Ruchi's flat file load # Tony Heskett 30 Jan 92 # our flat file FILE=foo # some test data cat > ${FILE} <<EOF Uabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi Uabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi Dabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi Dabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi Dabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi Uabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi Dabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi Dabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi Uabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi Uabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi EOF # write all output here exec 1>load.sql echo '' echo '' # assume lines to update start with U grep '^U' ${FILE} | sed -e 's/^.//' \\ -e 's/^..../"&","/' \\ -e 's/^............./&","/' \\ -e 's/^............................/&","/' \\ -e 's/^........................................./&","/' \\ -e 's/.*/update tbl set (col1, col2, col3, col4, col5) = (&");/' echo '' echo '' # assume lines to delete start with D grep '^D' ${FILE} | sed -e 's/^.//' \\ -e 's/^..../col1 = "&" and col2 = "/' \\ -e 's/^.............................../&" and col3 = "/' \\ -e 's/^\\(.........................................................\\).*/\\1";/' \\ -e 's/.*/delete from tbl where &/' \\ < delete.dat