Sponsored Content
Top Forums Shell Programming and Scripting perl search and replace - search in first line and replance in 2nd line Post 302493947 by durden_tyler on Friday 4th of February 2011 09:37:33 AM
Old 02-04-2011
Code:
$
$
$ # show the contents of the data file called "f4"
$
$ cat f4
tmp,123 --- if match tmp,??? then replace below line
,10:1 --- replace as ,10:50
abc,666
,10:1
tmp,111 --- if match tmp,??? then replace below line
,10:1 --- replace as ,10:50
tmp,123 --- if match tmp,??? then replace below line
,10:1 --- replace as ,10:50
aaa,666
,10:1 -- do not replace as above line is not matching "tmp,???"
,10:1 -- do not replace as above line is not matching "tmp,???"
$
$
$ # run the Perl one-liner that processes the data in the file "f4"
$
$ perl -plne 'if(/^tmp,\d{3}/) {$x=1} elsif($x) {$_=",10:50"; $x=0}' f4
tmp,123 --- if match tmp,??? then replace below line
,10:50
abc,666
,10:1
tmp,111 --- if match tmp,??? then replace below line
,10:50
tmp,123 --- if match tmp,??? then replace below line
,10:50
aaa,666
,10:1 -- do not replace as above line is not matching "tmp,???"
,10:1 -- do not replace as above line is not matching "tmp,???"
$
$

tyler_durden
 

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

Perl Search and replace entire line

I have a perl function in my script that needs to replace an entire line in a file sub changestate { my $base = (); my @base = (); open(BASE, $file) || die("Could not open file!"); @base=<BASE>; close (BASE); foreach $base(@base) { if($base =~... (1 Reply)
Discussion started by: insania
1 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 script to search a line and copy it to another line

Hi I have a log file (say log.txt). I have to search for a line which has the string ( say ERROR) in the log file and copy 15 lines after this into another file (say error.txt). Can someone give me the code and this has to be in PERL Thanks in advance Ammu (3 Replies)
Discussion started by: ammu
3 Replies

6. UNIX for Advanced & Expert Users

Search Parameter in first line and replace next line content

Hi, I need help. I have XML file as below &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... (4 Replies)
Discussion started by: rdtrivedi
4 Replies

7. Shell Programming and Scripting

PERL or SHELL Scrript to search in Directories by taking line by line from a text file

Unix box server version *********** >uname -r B.11.00 >echo $SHELL /usr/bin/ksh --> in this server, I have the path like /IMbuild/dev/im0serv1 ---> in that directory I have the folders startup(.jsp files nearly 100 jsp's ) and scripts(contains .js files nearly 100 files) ... (9 Replies)
Discussion started by: pasam
9 Replies

8. UNIX for Advanced & Expert Users

Search and replace a line in perl

Hi All, i can replace a perticular value in sentence using perl. perl -pi -e 's/old/new/' sample.txt but i am not able to replace whole string by perl. file1 contains "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.147.109.211)(PORT=1526))(CONNECT_DATA=(SID= MWDBD22)))". i... (3 Replies)
Discussion started by: arindam guha
3 Replies

9. 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

10. 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
sagasu(1)																 sagasu(1)

NAME
sagasu - GNOME tool to find strings in multiple files SYNOPSIS
sagasu [string [dir]] DESCRIPTION
sagasu is a GNOME tool to find strings in a set of files. The user specifies the search directory and the set of files to be searched. Double-clicking on a search result launches a user command that can for example load the file in an editor at the appropriate line. The search can recurse into subdirectories and can optionally ignore CVS directories. Two optional command-line arguments can be given: the first is the initial search string and the second is the directory whose files will be searched. If only one argument is given, it is taken as the search string. No search is actually started, but the appropriate fields are initialized. Any subsequent arguments are ignored. More documentation is available through the application's Help menu. OPTIONS
--help display a help page and exit --version display version information and exit LICENSE
This program is free software; you may redistribute it under the terms of the GNU General Public License. This program has absolutely no warranty. AUTHOR
Pierre Sarrazin See the Sagasu Home Page: http://sarrazip.com/dev/sagasu.html BUGS
The files to be searches are still assumed to be in Latin-1, not in UTF-8. The same goes for the command-line arguments and the terminal to which Sagasu is connected, if applicable. HISTORY
Sagasu is a Japanese word that means "to search." June 19th, 2010 sagasu(1)
All times are GMT -4. The time now is 12:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy