Inserting text in existing files
Posted in 1996
> > Hello unixers: > > I know that should be a easy way to do that, but I don't have enough > experience using the unix's stream utilities. > > I have a lot of INFORMIX-4GL programs without version control (SCCS) that I > would like to put in control. > > I have a text file (copyright) including the SCCS keywords and other general > information for all the files. > > I would like to insert this file in each 4GL program. I some situations I > have to change an special string in the files with the copyright file. > > Any help is welcome! > Interesting reply to address. Don't think I'll try it. Some time ago we faced this same situation. I did up an awk script at the time to add an 'ident' line to each 4gl program. You can modify it a bit to work for your situation. Either paste the block right into the awk code or use a getline to read it at the point you decide, Alternatively you can modify the shell to copy the code block and then append each new 4gl program and then move it to its old name - this later might be easier. addid_4gl.awk ------------------------------------- BEGIN { a=0 b=0 d=0} { c=0 if (($1 == "define" || $1 == "DEFINE") && a == 0) { a=1 c=1 print $0 print " ident char(80)," } if (index($0,",") == 0) { if (b == 0 && a == 1) { oldln=$0 print $0 > "/dev/tty" print "(B)efore, (A)fter, or [RETURN] (not yet): " > "/dev/tty" eof=getline ans < "/dev/tty" if (ans == "b" || ans == "B") { print "let ident = \\"@(#)$Header: $\\"" print oldln c=1 b=1 } if (ans == "a" || ans == "A") { print oldln print "let ident = \\"@(#)$Header: $\\"" c=1 b=1 } } } if ( c == 0 ) print $0 } ------------------------------------- The shell which wraps around this is: ------------------------------------- #!/bin/ksh while [ $# -gt 0 ] do rc=0 ext=${1##*.} echo $1 "Type - $ext" case "$ext" in "ace" ) awk -f $HOME/addid_ace.awk < $1 > $1.id rc=1 ;; "per" ) awk -f $HOME/addid_per.awk < $1 > $1.id rc=1 ;; "4gl" | "4gh" ) awk -f $HOME/addid_4gl.awk < $1 > $1.id rc=1 ;; "c" | "ec" ) awk -f $HOME/addid_c.awk < $1 > $1.id rc=1 ;; "*" | ? ) head $1 echo "Do a shell version? (y/n) \\c" read junk if [ "$junk" = "y" -o "$junk" = "Y" ] then awk -f $HOME/addid_sh.awk < $1 > $1.id rc=1 fi ;; esac if [ "$ext" = "$1" ] then echo "Do a shell version? (y/n) \\c" read junk if [ "$junk" = "y" -o "$junk" = "Y" ] then awk -f $HOME/addid_sh.awk < $1 > $1.id rc=1 fi fi echo $1 "rc :" $rc if [ $rc -eq 1 ] then mv $1.id $1 fi shift done ----------------------------------- cheers j. _____________________________________________________________________________ Jack Parker - Hewlett Packard, DMD/IS Boise, Idaho, USA jparker@hpbs3645.boi.hp.com _____________________________________________________________________________ If anything can go wrong, fix it. To hell with Murphy. _____________________________________________________________________________ Any opinions expressed herein are my own and not those of my employers. _____________________________________________________________________________