Home » Infrastructure » Unix » Read and Write to same file in Unix Shell Script (SCO unix)
Read and Write to same file in Unix Shell Script [message #314384] Wed, 16 April 2008 09:10 Go to next message
Messages: 11
Registered: January 2007
Junior Member
Situation is:
A batch program in Unix have created a file having records in it.
This file is flat file and data items in this file is position specific as per Low level document. One of the data item from position 2648-2665 is incorrect (length is 18 characters and data item is numeric). Incorrect means that this position should have decimal value but it is having whole number.

Plan is to write a sql script and pass the paramter to this sql script via shell script. The shell script will read from the file and pass the primary keys to sql script by traversing the line.
This sql script will find the correct information and pass back the correct value.

Capture this value and replace the value at the specific postion 2648-2665 by the capture value. Once all the file is read; save the file.

We have already completed with the sql script, passing the parameters and capturing the output parameters is not a problem. The problem here is we need to read and write to the same file.

Is it possbile?

Re: Read and Write to same file in Unix Shell Script [message #314471 is a reply to message #314384] Wed, 16 April 2008 17:10 Go to previous message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
I'd try external tables (but you'll need to write the result to another file). Renaming new-file to old-file effectively achieves what you want though.


sed is also a good option to consider, although you'll also need to catch output in a second file.
Previous Topic: looking for dbstart and dbshut syntax
Next Topic: Starting & Stopping DB using Script
Goto Forum:

Current Time: Thu Mar 23 06:02:59 CDT 2023