Adding the code after searching the string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding the code after searching the string
# 1  
Old 06-05-2013
add the code after 3 lines of searched line

Hi All,
please suggest me..

How to add the text from one file to another file and need to add the code after 3 lines of below searched line .

sample code in standard file:
Code:
<corecom:Description xml:id="id_2607">
<xsl:value-of select="./changeABO:AffectedItem/changeABO:TitleBlock/itemABO:Description" xml:id="id_2608"/>
</corecom:Description>
</xsl:if>
</corecom:ItemIdentification>
<xsl:if test="./changeABO:AffectedItem/changeABO:TitleBlock/itemABO:LifecyclePhase" xml:id="id_2609">  ---- Searched line..
<xsl:variable name="varItemLifeCyclePhase" xml:id="id_2610">
<xsl:value-of select="./changeABO:AffectedItem/changeABO:TitleBlock/itemABO:LifecyclePhase" xml:id="id_2611"/>
</xsl:variable>

---- Here We need to add the custom code from custom file-----
Code:
<!--SGI: customization for Lifecyclephase begin--> 
<RemanFlagVal> 
<xsl:value-of select="/changeABO:AffectedItem/changeABO:PageTwo/List22"/>
</RemanFlagVal>


Last edited by Scott; 06-05-2013 at 07:07 PM.. Reason: Please use code tags
# 2  
Old 06-05-2013
Sorry - not the slightest clue what you are talking of. Please provide input and desired output samples, and whatever you have tried so far, plus explain the logics in plain English.
# 3  
Old 06-05-2013
1. Agree with RudiC. What are you trying to achieve here?
2. What have you tried so far?
# 4  
Old 06-05-2013
Sounds like copy the file and insert the 4 lines after some part of the XML. We can assume the XML will line-fold as shown always, I guess.
Code:
sed '
    /<xsl:if test="\.\/changeABO:AffectedItem\/changeABO:TitleBlock\/itemABO:LifecyclePhase" xml:id="[^"]*">/{
        :loop
        /<\/xsl:variable>/!{
            N
            b loop
            }
        s/$/\
<!--SGI: customization for Lifecyclephase begin--> \
<RemanFlagVal> \
<xsl:value-of select="\/changeABO:AffectedItem\/changeABO:PageTwo\/List22"\/>\
<\/RemanFlagVal>/
   }
  ' infile >outfile

# 5  
Old 06-05-2013
Here is an approach using awk:
Code:
awk '/Search String/{R=NR}(NR-R)==3&&R{$0="Custom Code" RS $0;R=0}1' file

# 6  
Old 06-06-2013
thanks for reply.

But we can copy the code from customfile to standard file.

Code:
awk '/"<xsl:if test="./changeABO:AffectedItem/changeABO:TitleBlock/itemABO:LifecyclePhase""/{R=NR}
(NR-R)==3&&R{$0="echo `cat /home/oracle/DBA/sh/need2add.txt`" RS $0;R=0}1' AgileCreateEngineeringChangeOrderListABM_to_CreateEngineeringChangeOrderListEBM.xsl

Above command is modified and pasted .

1)Is it correct?

please suggest..

---------- Post updated at 03:59 AM ---------- Previous update was at 03:49 AM ----------

I have executed above command , getting below error .

Code:
oracle@dv-agiledb01-dc21:~/DBA/sh> sh -x 1.sh
+ awk '"/<xsl:if test="./changeABO:AffectedItem/changeABO:TitleBlock/itemABO:LifecyclePhase"/{R=NR}(NR-R)==3&&R{$0="cat /home/oracle/DBA/sh/need2add.txt" RS $0;R=0}1' AgileCreateEngineeringChangeOrderListABM_to_CreateEngineeringChangeOrderListEBM.xsl
awk: "/<xsl:if test="./changeABO:AffectedItem/changeABO:TitleBlock/itemABO:LifecyclePhase"/{R=NR}(NR-R)==3&&R{$0="cat /home/oracle/DBA/sh/need2add.txt" RS $0;R=0}1
awk:                 ^ syntax error
awk: "/<xsl:if test="./changeABO:AffectedItem/changeABO:TitleBlock/itemABO:LifecyclePhase"/{R=NR}(NR-R)==3&&R{$0="cat /home/oracle/DBA/sh/need2add.txt" RS $0;R=0}1
awk:                                                   ^ syntax error
awk: "/<xsl:if test="./changeABO:AffectedItem/changeABO:TitleBlock/itemABO:LifecyclePhase"/{R=NR}(NR-R)==3&&R{$0="cat /home/oracle/DBA/sh/need2add.txt" RS $0;R=0}1
awk:                                                                      ^ syntax error
awk: "/<xsl:if test="./changeABO:AffectedItem/changeABO:TitleBlock/itemABO:LifecyclePhase"/{R=NR}(NR-R)==3&&R{$0="cat /home/oracle/DBA/sh/need2add.txt" RS $0;R=0}1
awk:                                                                                                                                              ^ syntax error
awk: "/<xsl:if test="./changeABO:AffectedItem/changeABO:TitleBlock/itemABO:LifecyclePhase"/{R=NR}(NR-R)==3&&R{$0="cat /home/oracle/DBA/sh/need2add.txt" RS $0;R=0}1
awk:                                                                                                                                                  ^ unterminated string


Last edited by Scott; 06-06-2013 at 06:09 AM.. Reason: Please use code tags and take the time to format your posts so they are readable
# 7  
Old 06-10-2013
Quoting looks crazy?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add the code above searching string

Hi Team, I have one requirement. i have to add the code from file1.txt to file2.txt. based on searching string in file2.txt Conditions: 1) we have to add the code after and before searching string. 2) if the searching string find 3 times , we have to add the code after and before... (4 Replies)
Discussion started by: vijayko
4 Replies

2. UNIX for Dummies Questions & Answers

Need help searching for values in file then adding to line

Hello! I'm currently trying to organize data for some bio research, but I'm not sure how to compare a value to values in a file. So what I have are 2 arrays, one array contains NM numbers and can be referenced as NM. The other array has symbols, SYM. I have a file for which it contains an NM... (1 Reply)
Discussion started by: ShiGua
1 Replies

3. Shell Programming and Scripting

Searching for string between two different strings

I want to the following results using unix script, can some one help ? Thanks Input: select col1, col2 from tab1 where ......... select col1,.....,coln from tab2, tab3 where.... select clo1,clo2,col3 from tab4 where... output (results) tab1 tab2 tab3 tab4 basically I need... (5 Replies)
Discussion started by: kanagalav
5 Replies

4. Shell Programming and Scripting

Searching a String

Hi everyone ! suppose i'm searching for a specific string in a file so it is very easy, i use the following command grep 'keyword' file_name but how to search a word which is repeated maximum number of times in a file, for example in the following text i have to search a word which is... (12 Replies)
Discussion started by: ourned
12 Replies

5. Shell Programming and Scripting

searching the required string and appending string to it.

Hi all, I have some data in the form of adc|nvhs|nahssn|njadnk|nkfds in the above data i need to write a script so thet it will append "|||" to the third occurnace in the string ..... the outout should look like adc|nvhs|nahssn||||njadnk|nkfds Thanks, Firestar. (6 Replies)
Discussion started by: firestar
6 Replies

6. Shell Programming and Scripting

searching a text string for n'th :

hello, i'm a novice on bsh scripting so thanks for any help here basically i have a shell var $x that looks like this > echo $x nabc1234:!:73394:17155:Gary Mason:/home/garym:/bin/ksh and i'm trying to keep the first 8 characters and the text from the 4th : to the 5th : i've been trying... (9 Replies)
Discussion started by: sasglm
9 Replies

7. Shell Programming and Scripting

searching each file for a string

Hi Guys... I want to search for each file that contains a particular string. e.g find . -print | xargs grep -i string_name Now my issue is the files that I search in are gzipped. Will I be able to find the string, using the above commands, even if the files are gzipped? Please... (2 Replies)
Discussion started by: Phuti
2 Replies

8. Shell Programming and Scripting

Searching a string in a file

Hi, I am new to unix shell scripting. I have a requirement. Could anyone help me writing the script for the same? Here goes the requirement: I have a config file let's say temp.config. Here is the data in the config file temp.config : ------------- name=victor age=42 state=texas... (5 Replies)
Discussion started by: badrimohanty
5 Replies

9. UNIX for Dummies Questions & Answers

Searching for a string variable

Hi ... I have a string variable STR = "This is a test message" I have a file abc.txt that I am searching for the occurence of the string STR ... I am using the command in a script cat abc.txt | grep $STR It identifies each space as a seperator and prints word by word. How to... (2 Replies)
Discussion started by: mattrix
2 Replies

10. Shell Programming and Scripting

Extracting a string from one file and searching the same string in other files

Hi, Need to extract a string from one file and search the same in other files. Ex: I have file1 of hundred lines with no delimiters not even space. I have 3 more files. I should get 1 to 10 characters say substring from each line of file1 and search that string in rest of the files and get... (1 Reply)
Discussion started by: mohancrr
1 Replies
Login or Register to Ask a Question