nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

find a word in a file, and change a word beneath it ??

This is a discussion on find a word in a file, and change a word beneath it ?? within the Shell scripting forums, part of the Development/Scripting category; Hi all, I have a file with lines written somewhat like this. Code: aaaa ccc aa linux browse = no ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 13-02-2008, 07:24 PM
Member
User
 
Join Date: Oct 2007
OS: Linux RHEL 5
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
vikas027 is on a distinguished road
Unhappy find a word in a file, and change a word beneath it ??

Hi all,

I have a file with lines written somewhat like this.

Code:
aaaa
ccc
aa
linux
browse = no
xssxw
cdcedc
dcsdcd
csdw
police
dwed
dwd
browse = no


cdecec
dsdc
cdc
wd

wdcew
dwed
market
browse = yes

dwdw
wedwe
we
I would like to search word police (which is in middle of file)
and then change the line from browse = no to browse = yes which is after two lines from the word police.

Pls help... I am not so advanced in scripting.

Thanks in advance,
Vikas
Reply With Quote
  #2 (permalink)  
Old 13-02-2008, 09:30 PM
agn agn is offline
Member
User
 
Join Date: Feb 2008
OS: OpenBSD/FreeBSD/Debian/Fedora/RHEL
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 3
agn is on a distinguished road
Default

Code:
sed '/police/,/^browse/ s/no/yes/' filename
Try that.

Last edited by agn; 13-02-2008 at 11:28 PM.
Reply With Quote
  #3 (permalink)  
Old 14-02-2008, 12:53 AM
Member
User
 
Join Date: Oct 2007
OS: Linux RHEL 5
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
vikas027 is on a distinguished road
Wink

Quote:
Originally Posted by agn View Post
Code:
sed '/police/,/^browse/ s/no/yes/' filename
Try that.

thanks a lot,
will try this code & revert.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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 Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
To find and replace in text file nashtech Shell scripting 5 31-01-2010 06:32 AM
word search in file chandanperl Coding in General 2 11-03-2008 10:16 AM
can not find the username in /etc/passwd file subrata1in Getting started tutorials 5 27-03-2007 11:45 AM
can not find user name in /etc/passwd file subrata1in Linux software 2 26-03-2007 10:44 AM
user pass word sparky Shell scripting 1 26-06-2006 07:19 PM


All times are GMT +5.5. The time now is 06:05 PM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38