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
setmaillist(1)						      General Commands Manual						    setmaillist(1)

NAME
setmaillist - create a binary mailing list SYNOPSIS
setmaillist bin tmp DESCRIPTION
setmaillist reads a mailing list from its standard input. setmaillist writes the mailing list in a binary format to tmp; it then moves tmp to bin. tmp and bin must be on the same filesystem. If there is a problem creating tmp, setmaillist complains and leaves bin alone. The binary mailing list format is portable across machines. setmaillist always creates bin world-readable. MAILING LIST FORMAT
The mailing list read by setmaillist is a series of lines. NUL bytes are not allowed. If a line begins with a dot or slash, setmaillist takes the entire line as an include file name. If a line begins with an ampersand, setmaillist takes the rest of the line as a recipient address. If a line begins with a letter or num- ber, setmaillist takes the entire line as a recipient address. Each recipient address must include a fully qualified domain name. Recipi- ent addresses longer than 800 bytes are not allowed. setmaillist ignores blank lines and lines beginning with #. It also ignores spaces and tabs at the ends of lines. For example, god@heaven.af.mil djb@silverton.berkeley.edu is a mailing list with two addresses. SEE ALSO
setforward(1), newinclude(1), printmaillist(1) setmaillist(1)
All times are GMT -4. The time now is 03:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy