Sponsored Content
Full Discussion: sed or awk script problem
Top Forums Shell Programming and Scripting sed or awk script problem Post 302962502 by kshitij on Tuesday 15th of December 2015 07:04:27 AM
Old 12-15-2015
Wrench sed or awk script problem

Hi All

I am having a file as shown below

File1#

Code:
modyle 1 {
test jsj
hhsjh 13e3 
jsjjs 

}

memP(dbg_trace) {
ajjs
jsjs
jsjs

Test(claer) {
jsjs
}
TestStep ( RunTime ) {
RUN jksj
Controller (ddd) {
akk sns
sjsj
}
Controller (ddssd) {
akk sns
sjsj
}
Controller (ddssssd) {
akk sns
sjsj
}
}
}


modyless 2 {
test jsj
hhsjh 13e3 
jsjjs 

}


memP(dbg66_trace) {
ajjs
jsjs
jsjs

Test(claer) {
jsjs
}
TestStep ( RunTime ) {
RUN jksj
Controller (ddssd) {
akkss snss
sjssj
}
Controller (ddssssd) {
aksk snss
sssjsj
}
Controller (ssddssssd) {
askk ssns
ssjssj
}
}
}

modyless 3 {
test jsj
hhsjh 13e3 
jsjjs 

}

I am having another file as shown below

File 2 #


Code:
TestStep(RunExtra) {
      RunMode : RunTProg;
      Controller(WBP0) {
        ComparesGOID : On;
        ComparesGo : On;
          }
}

Now I want to insert File2 content in the File1 content
with a pattern match , Pattern match is complex

First we should match "memP" in File1 then it should check the last bracket "}" in memP wrapper and then insert the File Content "File2" before that "}"

Output File should be like this

File3 :

Code:
modyle 1 {
test jsj
hhsjh 13e3 
jsjjs 

}

memP(dbg_trace) {
ajjs
jsjs
jsjs

Test(claer) {
jsjs
}
TestStep ( RunTime ) {
RUN jksj
Controller (ddd) {
akk sns
sjsj
}
Controller (ddssd) {
akk sns
sjsj
}
Controller (ddssssd) {
akk sns
sjsj
}
}

TestStep(RunExtra) {
      RunMode : RunTProg;
      Controller(WBP0) {
        ComparesGOID : On;
        ComparesGo : On;
          }
}

}


modyless 2 {
test jsj
hhsjh 13e3 
jsjjs 

}


memP(dbg66_trace) {
ajjs
jsjs
jsjs

Test(claer) {
jsjs
}
TestStep ( RunTime ) {
RUN jksj
Controller (ddssd) {
akkss snss
sjssj
}
Controller (ddssssd) {
aksk snss
sssjsj
}
Controller (ssddssssd) {
askk ssns
ssjssj
}
}
TestStep(RunExtra) {
      RunMode : RunTProg;
      Controller(WBP0) {
        ComparesGOID : On;
        ComparesGo : On;
          }
}



}

modyless 3 {
test jsj
hhsjh 13e3 
jsjjs 

}

Colored one is new content which is being put

I tried below script
sed '/memP/ r File2' File1 > output.txt
But it is not selecting the last bracket in the memP wrapper

Please provide me your valuable suggestions
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

sed/awk String problem

I would appreciate it if any one can guide me in using awk perhaps sed in extracting some values from a long string. here is an example. .......some lines here........ ........ aaaa bbbb cccc ddddd eeeee fffff gggg (time:hhhh)........ ......some lines here also.......... How can I extract... (2 Replies)
Discussion started by: odogbolu98
2 Replies

2. Shell Programming and Scripting

awk & sed problem

Hello, I am new to shell scripting. I want to optimize my one of the script. I have one file and i want to remove selected zones for domains from that file.In this file i have almost 3500 zones for domains.Sample data for the file.... named.backup... (0 Replies)
Discussion started by: nrbhole
0 Replies

3. Shell Programming and Scripting

awk,sed or cut problem

Good afternoon, Sir's, I would like to seek your assistance regarding on this matter. $cat file1 111 aaaa bbb aass aaa files file1 temp temp1 pix 222 11 22 1 33 44 desired output: aaaa bbb aass files file1 temp1 222 11 22 1 33 44 thanks (7 Replies)
Discussion started by: invinzin21
7 Replies

4. Shell Programming and Scripting

awk...sed problem

Hi guys, I am tryingto delete or ignore columns in a large dataset using 'sed'. For example, I have the following dataset: - 20060714,X.XX,1,043004,Q,T,24.0000,1,25.5000,4, 20060714,X.XX,1,081209,Q,T,24.0000,1,25.5000,5, As you can see, there are 10 columns here and the table that I am... (1 Reply)
Discussion started by: aarif
1 Replies

5. Shell Programming and Scripting

Problem facing with sed and awk

Hi All, I have a got a problem .. I have t files as below: 1.txt contains ----- ----- ----- column 1, "cat", column 24, "dog", column 100, "rat", ----- ----- ----- 2.sh should contain ----- ----- ----- awk 'BEGIN { printf ("%1s","cat")}' (19 Replies)
Discussion started by: jisha
19 Replies

6. Shell Programming and Scripting

awk and sed problem

Hi, I am able to generate a csv file which has 3 columns. But the header is not coming out exactly i.e it doesnot have a comma in between it but the data is getting produced with the comma. The first line i.e the header is coming out as:- Counter Number Counterparty1 Counterparty2 ... (10 Replies)
Discussion started by: scripter12
10 Replies

7. Shell Programming and Scripting

awk/sed problem

I have a bunch of files I need to change a letter to another letter only in the first column of a space delimited file. The problem is that after the first column, there's comments and such that cause problems with awk. Here's what my data looks like: 16a28.0a27.0a26.0a25.0a24.67.255.200... (3 Replies)
Discussion started by: supradave
3 Replies

8. Shell Programming and Scripting

Some problem with awk or sed in if conditions

#set -x path=`pwd` while read line do dd=`echo $line|awk -F"," '{print $1}'|awk -F"/" '{print $2}'` if then mm=`echo $line|awk -F"," '{print $1}'|awk -F"/" '{print $1}'` yy=`echo $line|awk -F"," '{print $1}'|awk -F"/" '{print $3}'` var=`echo $line|awk -F"," '{print $2}'` var1=`echo... (2 Replies)
Discussion started by: nikhil jain
2 Replies

9. Shell Programming and Scripting

Problem with output awk and sed

I have file, i am extracting email address from file. but problem is that output is very ugly. I am using this command REMOVED "CSS OFFENDING CODE"... While original filename have no such character. Please suggest. (20 Replies)
Discussion started by: learnbash
20 Replies

10. Shell Programming and Scripting

Problem in formatting output in sed / awk

I have a file like this : ! 1 ! 542255 ! 50,140.00 ! ! 2 ! 551717 ! 5,805.00 ! ! 3 ! 551763 ! 8,130.00 ! ! 4 ! 551779 ! 750.00 ! ! 5 ! 551810 ! 56,580.00 ! ! 6 ! 551816 ! 1,350.00 ! ! 7 ! 551876 ! 360.00 ! ! 8 ! 551898 ! ... (10 Replies)
Discussion started by: adam1969in
10 Replies
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 08:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy