Home » Infrastructure » Unix » Updating a file in UNIX
Updating a file in UNIX [message #119561] Fri, 13 May 2005 06:55 Go to next message
mrinalkumar01
Messages: 6
Registered: April 2005
Junior Member
Hi,
I have a Pipe ("|") separated file in UNIX named Status, which contains month and status and which looks like
200501|E
200502|L
200503|U
200504|U

I want to update the second "|" separated field (Status) in one of the records.

Ex. I want to update the status of record of month 200503
I dont have access to any database on this server and i have to do this uing unix only.

Please let me know how to do this.
Thanks in Advance



Re: Updating a file in UNIX [message #119637 is a reply to message #119561] Fri, 13 May 2005 10:30 Go to previous messageGo to next message
Frank Naude
Messages: 4579
Registered: April 1998
Senior Member
Try something like this:

#!/bin/ksh

IFS="|"

cat input | while read month status
do
  if [ "$month" == "200503" ]; then
     status=X
  fi
  echo "$month|$status" >>output
done


Best regards.

Frank
Re: Updating a file in UNIX [message #119813 is a reply to message #119561] Mon, 16 May 2005 01:37 Go to previous message
mrinalkumar01
Messages: 6
Registered: April 2005
Junior Member
It works,

Thanks Frank, for the Excellent Logic.

I have now written a function and upgraded it to insert/update depending o presence of key

Regards
Mrinal
Previous Topic: Basics URGENT!!! PLz
Next Topic: Installation of Forms 6i on Redhat Linux 9/EL 3.0
Goto Forum:
  


Current Time: Wed Apr 24 16:14:05 CDT 2024