nixCraft Linux Forum

nixCraft

Linux 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

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 02-13-2008, 07:24 PM
Member
User
 
Join Date: Oct 2007
My distro: Linux RHEL 5
Posts: 33
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
Sponsored Links
  #2 (permalink)  
Old 02-13-2008, 09:30 PM
agn agn is offline
Member
User
 
Join Date: Feb 2008
My distro: OpenBSD/FreeBSD/Debian/Fedora/RHEL
Posts: 69
Rep Power: 1
agn is on a distinguished road
Default

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

Last edited by agn; 02-13-2008 at 11:28 PM.
Reply With Quote
  #3 (permalink)  
Old 02-14-2008, 12:53 AM
Member
User
 
Join Date: Oct 2007
My distro: Linux RHEL 5
Posts: 33
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

Bookmarks


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 On

Similar Threads

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


All times are GMT +5.5. The time now is 12:16 AM.


Powered by vBulletin® Version 3.7.2 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

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