Writing and Modifying Data In File

Modifying a particular data in a line contained in File 

I have a file containing data:

systemname/userid/password/comment
systemname1/userid1/password1/comment1
systemname2/userid2/password2/comment2

I want to modify the "password" using script.

Something like this would do the trick:

Code:

sed '/userid/s/oldpasswd/newpasswd/' inputfile > tempfile && \
cp tempfile inputfile && \
rm tempfileWhere the /userid/ means that the sed statement will only replace (substitute) "oldpasswd" with "newpasswd" for the userid given and not any other.
 

Writing data in a text file at particular line 

I need to write value of variable $version at a particular line in a text file.
Line number is determined by another variable &line......I don't know how to do it in shell script.

Try something like this:

Code:
sed $line'{
a\
'$version'
}' filename
 

AWK Help- Writing Data into a File 

I need to maintain a AUDIT file in system for every incoming and outgoing file. For this I am trying to append a record by using the AWK every time the file arriving.

I have used the code as below.
AWK '{print "FILENAME IS", $1,"DATE IS", $2}' >> AUDITFILE.txt

$1 and $2 are global variables from the previous line of code.

The above one is waiting for some more input and I don't now how to close the command.

At the end AUDITFILE is creating with no records.

How to append the data into a file by using the AWK?

You can use echo instead of awk
echo "FILENAME IS $1 DATE IS $2" >> AUDITFILE.txt

Usage of awk is either on the output of a command like
echo FIRST SECOND|awk '{print $1 $2}'

Or on a file like

awk '{print $1 $2}' filename

Have a Unix Problem
Unix Forum - Do you have a UNIX Question?

Unix Books :-
UNIX Programming, Certification, System Administration, Performance Tuning Reference Books

Return to : - Unix System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.