Sponsored Content
Top Forums Shell Programming and Scripting find a word in a file, and change a word beneath it ?? Post 302167046 by otheus on Wednesday 13th of February 2008 10:23:34 AM
Old 02-13-2008
Quote:
Originally Posted by vikas027
Hi all,

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.
Code:
awk '/^police$/ { browse=1; } browse==1 && /^browse/ { print "browse = yes"; browse=0; next; } 1'  <infile >outfile

So search for "police"; when found, change the "state". If in this special state, and the line starts with "browse", print out our special version instead and skip to the next line (skipping the next step). The trailing 1 is the next step which always prints out the current line.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies

2. Shell Programming and Scripting

How to find the word and change it

Hi, I am writing a script where, i want to parse through $JAVA_OPTS, if it finds the word -cleint it should return "no change needed" or else it should print "change needed". I tried a lot, but could not get the proper output. I am new to unix shell. If u guys can guide me it would be of gr8... (4 Replies)
Discussion started by: asirohi
4 Replies

3. Shell Programming and Scripting

To read data word by word from given file & storing in variables

File having data in following format : file name : file.txt -------------------- 111111;name1 222222;name2 333333;name3 I want to read this file so that I can split these into two paramaters i.e. 111111 & name1 into two different variables(say value1 & value2). i.e val1=11111 &... (2 Replies)
Discussion started by: sjoshi98
2 Replies

4. Shell Programming and Scripting

Find and replace a word in all the files (that contain the word) under a directory

Hi Everyone, I am looking for a simple way for replacing all the files under a directory that use the server "xsgd1234dap" with "xsdr3423pap". For Example: In the Directory, $pwd /home/nick $ grep -l "xsgd1234dap" *.sh | wc -l 119 I have "119" files that are still using... (5 Replies)
Discussion started by: filter
5 Replies

5. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

6. Shell Programming and Scripting

perl lwp find word and print next word :)

hi all, I'm new there, I'm just playing with perl and lwp and I just successfully created a script for log in to a web site with post. I have a response but I would like to have something like this: I have in my response lines like: <div class="sender">mimi020</div> <some html code.....>... (3 Replies)
Discussion started by: vogueestylee
3 Replies

7. Shell Programming and Scripting

Shell Script @ Find a key word and If the key word matches then replace next 7 lines only

Hi All, I have a XML file which is looks like as below. <<please see the attachment >> <?xml version="1.0" encoding="UTF-8"?> <esites> <esite> <name>XXX.com</name> <storeId>10001</storeId> <module> ... (4 Replies)
Discussion started by: Rajeev_hbk
4 Replies

8. Shell Programming and Scripting

Search for a specific word and print only the word from the input file

Hi, I have a sample file as shown below, I am looking for sed or any command which prints the complete word only from the input file. Ex: $ cat "sample.log" I am searching for a word which is present in this file We can do a pattern search using grep but I need to cut only the word which... (1 Reply)
Discussion started by: mohan_kumarcs
1 Replies

9. Shell Programming and Scripting

Find a word and increment the number in the word & save into new files

Hi All, I am looking for a perl/awk/sed command to auto-increment the numbers line in file, P1.tcl: run_build_model sparc_ifu_dec run_drc set_faults -model path_delay -atpg_effectiveness -fault_coverage add_delay_paths P1 set_atpg -abort_limit 1000 run_atpg -ndetects 1000 I would like... (6 Replies)
Discussion started by: jypark22
6 Replies

10. UNIX for Beginners Questions & Answers

UNIX script to check word count of each word in file

I am trying to figure out to find word count of each word from my file sample file hi how are you hi are you ok sample out put hi 1 how 1 are 1 you 1 hi 1 are 1 you 1 ok 1 wc -l filename is not helping , i think we will have to split the lines and count and then print and also... (4 Replies)
Discussion started by: mirwasim
4 Replies
DNSServiceBrowse(3DNS_SD)			      DNS Service Discovery Library Functions				 DNSServiceBrowse(3DNS_SD)

NAME
DNSServiceBrowse - browse service instances with DNS SYNOPSIS
cc [ flag ... ] file ... -ldns_sd [ library ... ] #include <dns_sd.h> DNSServiceErrorType DNSServiceBrowse(DNSServiceRef *sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, const char *regtype, const char *domain, DNSServiceServiceBrowseReply callBack, void *context); typedef void(*DNSServiceBrowseReply)(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *serviceName, const char *regtype, const char *replyDomain, void *context); DESCRIPTION
The DNSServiceBrowse() function is used to browse for service instances of a particular service and protocol type. The sdRef argument points to an uninitialized DNSServiceRef. If the call to DNSServiceBrowse succeeds sdRef is initialized. The flags argument to DNSService- Browse() is currently unused and reserved for future use. A nonzero value to interfaceIndex indicates DNSServiceBrowse() should do a browse on all interfaces. Most applications will use an interfaceIndex value of 0 to perform a browse on all interfaces. See the section "Con- stants for specifying an interface index" in <dns_sd.h> for more details. The callback function is invoked for every service instance found matching the service type and protocol. The callback argument points to a function of type DNSServiceBrowseReply listed above. The DNSServiceBrowse() call returns browse results asynchronously. The service browse call can be terminated by applications with a call to DNSServiceRefDeallocate(). The regtype parameter is used to specify the service type and protocol (e.g. _ftp._tcp). The protocol type must be TCP or UDP. The domain argument to DNSServiceBrowse() specifies the domain on which to browse for services. Most applications will not specify a domain and will perform a browse on the default domain(s). The context argument can be NULL and points to a value passed to the callback function. The sdRef argument passed to the callback function is initialized by DNSServiceBrowse() call. The possible values passed to flags in the callback function are: kDNSServiceFlagsMoreComing and kDNSServiceFlagsAdd. The kDNSServiceFlagsMoreComing value indicates to a callback that at least one more result is immediately available. The kDNSServiceFlagsAdd value indicates that a service instance was found. The errorCode argument will be kDNSServiceErr_NoError on success. Otherwise, failure is indicated. The discovered service name is returned to the callback via the serviceName argument. The regtype argument in the callback holds the service type of the found service instance. The discovered service type can be different from the requested service type in the browse request when the discovered service type has sub- types. The domain argument to the callback holds the domain name of the discovered service instance. The service type and the domain name must be stored and passed along with the service name to resolve a service instance using DNSServiceResolve(). RETURN VALUES
The DNSServiceBrowse function returns kDNSServiceErr_NoError on success. Otherwise, an error code defined in <dns_sd.h> is returned to indicate an error has occurred. When an error is returned by DNSServiceBrowse, the callback function is not invoked and the DNSServiceRef argument is not initialized. ATTRIBUTES
See attributes(5) for description of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Committed | +-----------------------------+-----------------------------+ |MT-Level |Safe | +-----------------------------+-----------------------------+ SEE ALSO
DNSServiceRefDeallocate(3DNS_SD), DNSServiceResolve(3DNS_SD), attributes(5) SunOS 5.11 20 Aug 2007 DNSServiceBrowse(3DNS_SD)
All times are GMT -4. The time now is 10:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy