File handling in Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File handling in Script
# 1  
Old 10-08-2008
Java 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

Code:
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.
# 2  
Old 10-08-2008
Some ideas i got ..... just try Smilie

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....
# 3  
Old 10-08-2008
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with shell script handling processes

Hello I have a file which has around 120 lines of commands. I am trying to write a shell script like which reads the 'command' file and executes line by line with some additional (common argument) with maximum 6 commands active at a time. Each of these commands when executed takes time... (5 Replies)
Discussion started by: JackyShane_36
5 Replies

2. Shell Programming and Scripting

Handling tape errors in script

AIX 7.1 Here's the script #!/bin/ksh find . -print > filelist.txt backup -ivqf/dev/rmt0 < filelist.txt > backup.log if ; then echo "Backup to tape failed!" >> backup.log else echo "Backup to tape successfull!" >> backup.log fi mail -v -s "Backup report" maillist < backup.log ... (4 Replies)
Discussion started by: landog
4 Replies

3. Shell Programming and Scripting

Help me add Error Handling to my script

Hi all, I have some sections of a script that I am trying to add error handling to. Basically if it returns any error, just continue. This is for a deployment script that i am writing to assist in the deployment of scripts out to other systems. At the top of my KSH script i added this... (5 Replies)
Discussion started by: nitrobass24
5 Replies

4. Shell Programming and Scripting

Expect Script Error Handling

Good Day Everyone, I was hoping to get a little insight into an expect script that I've written. Basically we have this expect script to perform an sftp upload, key authentication is not an option, and sftp is the only method supported by our vendor, thus the need for this. I want to be... (3 Replies)
Discussion started by: thaller
3 Replies

5. UNIX for Dummies Questions & Answers

File not found handling in ftp script

I have a pattern for filename to be searched. I need to get the files from remote server Who are matching the file pattern. And i need to exit with non zero return code for: 1)No files found matching that pattern 2)More than one files matching the name pattern. If only one files is... (1 Reply)
Discussion started by: pandeesh
1 Replies

6. Shell Programming and Scripting

Help with Error Handling on Script

Hi, I need your guys help again. I run a script which check for some process status in a loop. when i check the process some of the process could throw an error, how can i check that inside my script. Thanks, RR (3 Replies)
Discussion started by: rrb2009
3 Replies

7. UNIX for Dummies Questions & Answers

Handling input from a ls in a script

I'm trying to write a script that will handle the input from the ls command in my script so I can then manipulate the data. For example, I want to capture the output of the ls command in my script and then do a differences between the filename received in to another directory. ls |... (1 Reply)
Discussion started by: spookyrtd99
1 Replies

8. Shell Programming and Scripting

handling filespec in bash script

hi there, i just need a help handling the output of filespec in case has been picked im writing a bash script similar to the command ls, and ive done everything except handing the filespec which i spent more than 3 hrs and i coundn't figure out or find any on the net. all what i need is... (11 Replies)
Discussion started by: new2Linux
11 Replies

9. Shell Programming and Scripting

Shell script file handling

Hi ! /bin/sh set logdir1 "logDir/local/logname" #write the filename into a file echo $logdir1 >> logname.txt how do i exec the above echo command (1 Reply)
Discussion started by: nathgopi214
1 Replies

10. UNIX for Advanced & Expert Users

signal handling in shell script

Hi can any please tell me is it possible to catch the signal in a shell script like we do in C. if yes please give me some idea or a link. (4 Replies)
Discussion started by: Raom
4 Replies
Login or Register to Ask a Question