Sponsored Content
Top Forums Shell Programming and Scripting [Perl] Insert lines before lines. Post 302324279 by ejdv on Wednesday 10th of June 2009 11:28:43 AM
Old 06-10-2009
Quote:
Originally Posted by radoulov
Code:
perl -0pe'  
  s/bbbbb(?!.*bbbbb)/NEW_NEW_NEW\n$&/s
  ' infile

Thanks for the one-liner.
For this example it works, but you understand it is part of a bigger universe :-)
And I am having trouble incorporating it in the example code.
Not to mention that I do not understand the wizardry in your one-liner.
I understand it is a conditional substitute, but what is the $ and the & doing for example ?

But let me make the problem a bit more real life.

Here is the test.txt data file (edited for the forum).
It is a ksh script and this is how it comes after an installation.
I need to modify it and I would like to have this modification done by a script.

Code:
if [ -f $topload_inprogress ]
then
		blahlblah
		rm $inprogress
		exit 1
fi 

if [ ! -f $params ]
then
	blahlblah
	rm $inprogress
	exit 1
fi 

if(($?==1))
then 
	blahlblah
	rm $inprogress
	exit 1
fi

if [[ -f $ftp_fin ]]
then
	rm $ftp_fin
else
	blahlblah
	rm $inprogress
	exit 1
fi

files=`ls $CADATA/srcdata/$source/custom/BULK/after`
for name in $files
do
	blahlblah
done

rm $inprogress
$CAROOT/prog/ca_log_message TOPOLOGY_STAT "Finished the bulk ftp topology load of $source data source."
exit 0

I need to insert a block-text (6 lines) between last 'done' and the 'rm $inprogress'.

Can your "(?!.*bbbbb)" be of any help there ?

Greetings,

E.J.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to count lines - ignoring blank lines and commented lines

What is the command to count lines in a files, but ignore blank lines and commented lines? I have a file with 4 sections in it, and I want each section to be counted, not including the blank lines and comments... and then totalled at the end. Here is an example of what I would like my... (6 Replies)
Discussion started by: kthatch
6 Replies

2. Shell Programming and Scripting

Insert lines between delimiters

I'm working with a file like: somestuff somemorestuff ... someadditionalstuff STARTTAG ENDTAG someotherstuff somecoolstuff ... somefinalstuffI've got some text (either in a file or piped) to put between STARTTAG and ENDTAG. I was thinking something like grepping for the line number of... (2 Replies)
Discussion started by: BMDan
2 Replies

3. Shell Programming and Scripting

Insert Title To Each Lines

I have a command that returns following, but it's missing a title for each line. YOUR FULL NAME YOUR ID YOUR EMAIL YOUR ADDRESS YOUR PHONE Now, I want to add its title to each line: Name: YOUR FULL NAME ID: YOUR ID Email: YOUR EMAIL Address: YOUR ADDRESS Phone:... (2 Replies)
Discussion started by: tqlam
2 Replies

4. Shell Programming and Scripting

how to insert text between lines of an existing file using perl

Hi , I need some inputs on how to open a file (file.txt) and parse the text example aaa of the file and bbb of the file and add the text zzzz once i parse (aaa and bbb) and followed by the remaining of the text as it is in the file using perl programming. Thanks in advance (3 Replies)
Discussion started by: madhul2002
3 Replies

5. Shell Programming and Scripting

Insert between lines.

Hello...I'm here again. This is the situation I want check if exist text between two lines: Example: interface description --text to verify ip adress if not exists text between 'interface' and 'ip address' i want insert the word 'no description' interface no description --if not... (4 Replies)
Discussion started by: bobbasystem
4 Replies

6. Shell Programming and Scripting

Perl XML, find matching condition and grep lines and put the lines somewhere else

Hi, my xml files looks something like this <Instance Name="New York"> <Description></Description> <Instance Name="A"> <Description></Description> <PropertyValue Key="false" Name="Building A" /> </Instance> <Instance Name="B"> ... (4 Replies)
Discussion started by: tententen
4 Replies

7. Shell Programming and Scripting

[Perl] Split lines into array - variable line items - variable no of lines.

Hi, I have the following lines that I would like to see in an array for easy comparisons and printing: Example 1: field1,field2,field3,field4,field5 value1,value2,value3,value4,value5Example 2: field1,field3,field4,field2,field5,field6,field7... (7 Replies)
Discussion started by: ejdv
7 Replies

8. Shell Programming and Scripting

sed - insert two lines

I have done this sed command to insert one line after a specific string is found: sed '/patternstring/ a\ new line string' file1 But how do I insert two lines? This is not possible: sed '/patternstring/ a\ new line string \a new line string 2' file1 (2 Replies)
Discussion started by: locoroco
2 Replies

9. Shell Programming and Scripting

Insert few lines above a match using sed, and within a perl file.

Greetings all, I am trying to match a string, and after that insert a few lines above that match. The string is "Version 1.0.0". I need to insert a few lines ONLY above the first match (there are many Version numbers in the file). The rest of the matches must be ignored. The lines I need to... (2 Replies)
Discussion started by: nagaraj s
2 Replies

10. Shell Programming and Scripting

Insert text before first 'n' lines

I want to put a particular text, say, the hash '#' before each of the first n lines of a file. How can I do that? (4 Replies)
Discussion started by: hbar
4 Replies
insdelln(3XCURSES)					  X/Open Curses Library Functions					insdelln(3XCURSES)

NAME
insdelln, winsdelln - insert/delete lines to/from the window SYNOPSIS
cc [ flag... ] file... -I /usr/xpg4/include -L /usr/xpg4/lib -R /usr/xpg4/lib -lcurses [ library... ] c89 [ flag... ] file... -lcurses [ library... ] #include <curses.h> int insdelln(int n); int winsdelln(WINDOW *win, int n); PARAMETERS
n Is the number of lines to insert or delete (positive n inserts; negative n deletes). win Is a pointer to the window in which to insert or delete a line. DESCRIPTION
The insdelln() and winsdelln() functions insert or delete blank lines in stdscr or win, respectively. When n is positive, n lines are added before the current line and the bottom n lines are lost; when n is negative, n lines are deleted starting with the current line, the remaining lines are moved up, and the bottom n lines are cleared. The position of the cursor does not change. RETURN VALUES
On success, these functions return OK. Otherwise, they return ERR. ERRORS
None. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
deleteln(3XCURSES), insertln(3XCURSES), libcurses(3XCURSES), attributes(5), standards(5) SunOS 5.11 5 Jun 2002 insdelln(3XCURSES)
All times are GMT -4. The time now is 01:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy