Perl find text and add line


 
Thread Tools Search this Thread
Top Forums Programming Perl find text and add line
# 1  
Old 03-22-2013
Perl find text and add line

Hi All

I need to add a line to a file but after a certain block of text is found

The block of text looks like this

Code:
<RDF:Description RDF:about="urn:mimetype:video/quicktime"
                   NC:value="video/quicktime"

and i need to add this in the next line down ( note there is already something there so it need to be pushed down a line)

Code:
NC:useSystemDefault="true"


many thanks
A
# 2  
Old 03-22-2013
sed, ok?
Code:
sed '/NC:value="video/a NC:useSystemDefault="true"' file

# 3  
Old 03-22-2013
Quote:
Originally Posted by balajesuri
sed, ok?
Code:
sed '/NC:value="video/a NC:useSystemDefault="true"' file


sed it fine, i have not used it before like this, can explain what is it doing?
# 4  
Old 03-22-2013
RedHat

Code:
cat file1
abcd
efgh
<RDF:Description RDF:about="urn:mimetype:video/quicktime"
                   NC:value="video/quicktime"
ijkl

perl -pe 's!(NC:value="video/quicktime")!$1\nNC:useSystemDefault="true"!' file1
abcd
efgh
<RDF:Description RDF:about="urn:mimetype:video/quicktime"
                   NC:value="video/quicktime"
NC:useSystemDefault="true"
ijkl

# 5  
Old 03-22-2013
Code:
/NC:value="video/           ==> If this pattern is found
a                           ==> Append in the line next to the pattern
NC:useSystemDefault="true"  ==> With this text

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find line then evaluate text on next line, print when condition is met

Hello, I am looking for a specific situation in a text file. The conditions are, > <CompoundName> InChI=1S/C5H12NO2/c1-5(2)4-8-6(3)7/h5H,4H2,1-3H3/q+1 I am looking for cases where the line "> <CompoundName>" is followed by a line that contains the string "InChI=" without regard to... (5 Replies)
Discussion started by: LMHmedchem
5 Replies

2. Shell Programming and Scripting

How to add the line to previous line in | delimited text?

Hi All, I am new to Unix and I have one challenge and below are the details. I have pipe delimited text file in that data has span into multiple lines instead of single line. Sample data. Data should be like below for entire file. 41|216|398555|77|provided complete NP outcome data ... (21 Replies)
Discussion started by: Narasimhasss
21 Replies

3. Shell Programming and Scripting

How to add line breaks to perl command with large text in single quotes?

Below code extracts multiple field values from XML into array and prints all in one line. perl -nle '@r=/(?: jndiName| authDataAlias| value| minConnections| maxConnections| connectionTimeout| name)="(+)/g and print join ",",$ENV{tIPnSCOPE},$ENV{pr ovider},$ENV{impClassName},@r' server.xml ... (4 Replies)
Discussion started by: kchinnam
4 Replies

4. Shell Programming and Scripting

awk to skip lines find text and add text based on number

I am trying to use awk skip each line with a ## or # and check each line after for STB= and if that value in greater than or = to 0.8, then at the end of line the text "STRAND BIAS" is written in else "GOOD". So in the file of 4 entries attached. awk tried: awk NR > "##"' "#" -F"STB="... (6 Replies)
Discussion started by: cmccabe
6 Replies

5. Shell Programming and Scripting

How to find text and replace next line.?

Have multiple files with the same format and certain text is the same. Have specific text to search for and then need to replace the next line. Can search on the text DEVICE and multiple lines will be found. The line after each DEVICE line has {. Want to replace the line { with {-someadditiontext.... (2 Replies)
Discussion started by: bigdaddywags
2 Replies

6. Shell Programming and Scripting

how to add text into the last line of text file

I need help with insert text to the last line of text file with echo command I know can do something like echo "i4\n$logtext\n.\nwq" | ex -s $file can insert to first line, but how can i change this code in order to insert to the last line of text file? please help, thank you :( (2 Replies)
Discussion started by: gavin_L
2 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. Shell Programming and Scripting

find a certain line and append text to the end of the line

After I create printer queues in AIX, I have to append a filter file location within that printers custom file. within lets say test_queue.txt I need to find the row that starts with :699 and then I need to append on the end the string /usr/local/bin/k_portrait.sh. Now I've gotten the sed... (2 Replies)
Discussion started by: peachclift
2 Replies

9. Shell Programming and Scripting

Find and add/replace text in text files

Hi. I would like to have experts help on below action. I have text files in which page nubmers exists in form like PAGE : 1 PAGE : 2 PAGE : 3 and so on there is other text too. I would like to know is it possible to check the last occurance of Page... (6 Replies)
Discussion started by: lodhi1978
6 Replies

10. Shell Programming and Scripting

how to insert text before first line in perl

Hello all im doing simple parsing on text file , but now I need to insert string before the first line of the text file , how can I do that in perl? (3 Replies)
Discussion started by: umen
3 Replies
Login or Register to Ask a Question