UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 8th, 2012, 10:22 AM
Unixabc123 Unixabc123 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 Unixabc123 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 34 m 54 sec
Reputation Power: 0
Replace a line in a file

Hi All,

I have a quick question wrt to a specific scenario in UNIX where I am trying to loop through lines of a file and trying to replace the line with another

File :

abcd.sh:501:/export/home/test/scripts_test:N
load.sh:501:/export/home/test/scripts_test,UK:N
unload.sh:501:/export/home/test/scripts_test,UK,501:N
defs.sh:501:/export/home/test/scripts_test,UK,501:N
hjkl.sh:501:/export/home/test/scripts_test,UK,501:N
uio.sh:501:/export/home/test/scripts_test,UK,501:N
inmu.sh:501:/export/home/test/scripts_test,UK,501:N

Requirement:
Read each line of the file and based on the status of the script execution in field 1 of the above file update the last field in the file to F or S (failed or success) instead of "N"

The code should replace the current line in the file and not append to the file

I tried the sed -i option and it does not work and errors out.I tried an awk and it dint work as well

The Shell is a KSH

Code snippet I am using:

while read line
do
./$script_name $params
# echo $?
if [ $? -ne 0 ]
then
echo "Inside Updating status F"
awk NR==$line '{sub( "N" ,"F" ); print }' file.txt
done < file.txt


Looking forward to suggestions

Thanks

Reply With Quote
  #2  
Old November 8th, 2012, 02:53 PM
Unixabc123 Unixabc123 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 Unixabc123 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 34 m 54 sec
Reputation Power: 0
Hi,

I finally got this working using the

sed -i "s/$line/$line1/g" file

Thanks

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Replace a line in a file

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap