The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
automating file search and replace text ommatidia Shell Programming and Scripting 3 02-28-2008 04:40 PM
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 10:24 AM
Search and replace in file.. Amits Shell Programming and Scripting 2 08-22-2006 07:11 PM
Search and replace multi-line text in files marz Shell Programming and Scripting 10 10-10-2005 08:05 AM
How do you search and replace a text with markerA that end with markerB drone Shell Programming and Scripting 1 06-19-2003 09:12 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-25-2008
Vrgurav Vrgurav is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 6
How to search and replace text in same file

script is as below

v_process_run=5
typeset -i p_cnt=0
pdata=/home/proc_data.log

while [ $p_cnt -le $v_process_run ]
do
# execute script in background

dummy_test.sh "a1" "a2" &
p_cnt=$p_cnt+1

echo "data : $p_cnt : Y" >> $pdata

done



file created with following data in /home/proc_data.log
data : 1 : Y
data : 2 : Y
data : 3 : Y
data : 4 : Y
data : 5 : Y

now when each background process is completed
want to delete the line for matching pattern from log file without redirecting to new file ( below command is not working , please suggest)

for example :
grep "data : 3 : Y" /home/proc_data.log | sed "/data : 3 : Y/d"

or

now when each background process is completed
want to update the line for that process from log file
without redirecting to new file ( please suggest);

search for : data : 3 : Y
and relace with : data : 3 : N

hence output in the file should be

data : 1 : Y
data : 2 : Y
data : 3 : N
data : 4 : Y
data : 5 : Y
  #2 (permalink)  
Old 04-25-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,913
One way is to use ed(1). Here is a sample script to replace line 3 of your sample file with "hello there"
Code:
$ cat ed-script
/data : 3 : Y/c
hello there
.
w
q
$
Invoke script as follows
Code:
ed file < ed-script
Closed Thread

Bookmarks

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:38 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0