File handling in Script

Hi All,

How can we handle file operation in scripts. I have written a script that run ok otherwise however the "Cat" operation leaves a process open on the box. Command is like

cat "${LASTFILENAME}" |   /usr/xpg4/bin/awk -F, '{do{if ($3 == "100" && $4 == "300" && $170 ~ /^abc/) {
           OFS=",";
          for ( i=0; i<=6; i++ ) { $(95+i)=$(170+i); }
          for ( i=0; i<=21; i++ ) { $(168+i)=$(177+i); }
          print $0;
        }

Please suggest.

Some ideas i got ..... just try :slight_smile:

1) what ever out put you need to append to file you can redirect also

as

print $0 >> "${LASTFILENAME}"

2)otherwise i think you can add some lines to kill the file writting process by grep for the process id for the filename and kill the process at the end of all process...

But this need to after checking all process which gave during the ps -ef

i think after execting the script it will automatically end up....

first, awk can read files, no need to use cat!!!

awk --someoptions 'the awk program here' ${LASTFILENAME}

also, for a much better readability, is better to put all the awk commands in a file, and use the -f switch to read from there