Sponsored Content
Top Forums UNIX for Advanced & Expert Users Search Parameter in first line and replace next line content Post 302406643 by rdtrivedi on Tuesday 23rd of March 2010 03:04:34 PM
Old 03-23-2010
Thanks dennis.jacob and zaxxon for your time to help me. I am newbie in awk/sed/perl one liner world so unable to understand error on your solution.

I tried SED command as suggested but getting below error.

server:/home> sed '/ListenPort/{ n; s/21111/98765/ }' /tmp/xp.xml
sed: command garbled: /ListenPort/{ n s/21111/98765/ }

I tried AWK command as suggested but getting below error.

server:/home> awk 'f==1 {gsub(/21111/,"98765");f=0; } /ListenPort/ {f++}1' < /tmp/xp.xml > /tmp/xp1.xml
awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: bailing out near line 1

---------- Post updated at 12:04 PM ---------- Previous update was at 09:40 AM ----------

I need help. I have XML file as below

Code:

&lt;a n=&quot;infoLevel&quot;&gt;
&lt;v s=&quot;true&quot;/&gt;
&lt;/a&gt;
&lt;a n=&quot;localAddr&quot;&gt;
&lt;v s=&quot;server.host.com&quot;/&gt;
&lt;/a&gt;
&lt;a n=&quot;ListenPort&quot;&gt;
&lt;v s=&quot;21111&quot;/&gt;
&lt;/a&gt;


I need to find variable "ListenPort" in line and then replace next line's 21111 to 98765.

And, this problem is not to solve only one string "21111" but it can be any number between "0-99999". It means displayed problem has 21111 but it could be 1 or 23 or 456 or 7890 or 98711. The good part is starting position of first number is always fixed in that line. It means number always start from position 17 and has surrounded by "&quot;" string.

Please help me to solve this problem using sed/awk/perl.

Thanks in advance,
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

search and replace the whole line

Hi, I have this line in a file called test.cfg SOURCEFILE=/usr/platform/sun4v/driver/file.cfg But i have many occurances of "SOURCEFILE" in test.cfg , i need to search only for this line and replace that line with SOURCEFILE=/usr/platform/sun4x/driver/file.cfg again there are many... (17 Replies)
Discussion started by: Jartan
17 Replies

2. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies

3. Shell Programming and Scripting

How to replace a line content

Hi Experts, I have binary files contain an ID Line as: : : $Header: FNDSCMON.fmb 115.6 2000/01/11 10:26:10 pkm ship$ : : where the ID Line format is: $Header: <File_Name> <Version> <Last_update_date_time> pkm ship$ In this Example: File_Name = FNDSCMON.fmb Version = 115.6... (13 Replies)
Discussion started by: victorcheung
13 Replies

4. Shell Programming and Scripting

search for a string ,replace the whole line with new line

hai i am very new to unix. i am having two files like this. first.properties cache.ZA.TL_CCY=SELECT trim(CCY_CODE)||trim(COUNTRY_CODE)||trim(CITY_CODE) AS... (4 Replies)
Discussion started by: kkraja
4 Replies

5. Shell Programming and Scripting

perl search and replace - search in first line and replance in 2nd line

Dear All, i want to search particular string and want to replance next line value. following is the test file. search string is tmp,??? ,10:1 "???" may contain any 3 character it should remain the same and next line replace with ,10:50 tmp,123 --- if match tmp,??? then... (3 Replies)
Discussion started by: arvindng
3 Replies

6. Solaris

Line too long error Replace string with new line line character

I get a file which has all its content in a single row. The file contains xml data containing 3000 records, but all in a single row, making it difficult for Unix to Process the file. I decided to insert a new line character at all occurrences of a particular string in this file (say replacing... (4 Replies)
Discussion started by: ducati
4 Replies

7. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

8. Shell Programming and Scripting

Search text and replace line next to it

I have a file which requires modification via a shell script. Need to do the following: 0. take input from user for new text. 1. search for a keyword in the file. 2. replace the line next to this to this keyword with user supplied input. for e.g., my file has the following text: (some... (7 Replies)
Discussion started by: chingupt
7 Replies

9. Shell Programming and Scripting

Multiple line search, replace second line, using awk or sed

All, I appreciate any help you can offer here as this is well beyond my grasp of awk/sed... I have an input file similar to: &LOG &LOG Part: "@DB/TC10000021855/--F" &LOG &LOG &LOG Part: "@DB/TC10000021852/--F" &LOG Cloning_Action: RETAIN &LOG Part: "@DB/TCCP000010713/--A" &LOG &LOG... (5 Replies)
Discussion started by: KarmaPoliceT2
5 Replies

10. Shell Programming and Scripting

Help with replace comma with new line and repeat the content

Input file G A G A,T A C A G,T,C T C . . Desired Output file G A G A G T A C A G A T A C T C (4 Replies)
Discussion started by: perl_beginner
4 Replies
Net::Google::Code::Issue::Search(3pm)			User Contributed Perl Documentation		     Net::Google::Code::Issue::Search(3pm)

NAME
Net::Google::Code::Issue::Search - Issues Search API DESCRIPTION
INTERFACE
search ( can => 'all', q = 'foo', sort => '-modified', limit => 1000, load_after_search => 1 ) do the search, the results is set to $self->results, which is an arrayref with Net::Google::Code::Issue as element. If a "sort" argument is specified, that will be passed to google code's issue list. Generally, these are composed of "+" or "-" followed by a column name. limit => Num is to limit the results number. load_after_search => Bool is to state if we should call $issue->load after search return true if search is successful, false on the other hand. updated_after( date_string || DateTime object ) find all the issues that have been updated or created after the date. the issues are all loaded. return true if success, false on the other hand project results this should be called after a successful search. returns issues as a arrayref. AUTHOR
sunnavy "<sunnavy@bestpractical.com>" LICENCE AND COPYRIGHT
Copyright 2008-2010 Best Practical Solutions. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.1 2010-01-29 Net::Google::Code::Issue::Search(3pm)
All times are GMT -4. The time now is 06:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy