Need Help On REG EXP in unix

 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support Need Help On REG EXP in unix
# 1  
Old 02-15-2012
Need Help On REG EXP in unix

Respected All,

I have a very big xml in that i want to search only below 3 lines.

<target name ="UpgradePrimaryBox" depends ="configureBox1">
<echo> Finished Upgrading Primary Box </echo>
</target>

grep -i "<target.*UpgradePrimaryBox" this gives me the first line.
then i need to match second line and the </target>.

Please help me.

Thanks,
Amey
# 2  
Old 02-15-2012
Hi ameyrk,

There is an option that print following lines of a match. I don't know if your version support it. Try it:
Code:
$ grep -A2 -i "<target.*UpgradePrimaryBox"

Regards,
Birei
# 3  
Old 02-15-2012
Birei,

correct my version does not support.

my question is like grep -i "<target.*UpgradePrimaryBox<followed by new line><then followed by target>"

any help?
# 4  
Old 02-15-2012
grep matches lines. If what you want isn't a matching line, it doesn't really do it. It's not a programming language, you can't tell it "if x, print two more lines."

awk is a programming language however. You can tell it "if x, print 2 more lines".

Code:
awk '/<target.*UpgradePrimaryBox/ { print; getline; print; getline ; print }' file

# 5  
Old 02-15-2012
Wow that really worked. In this case we know there are 3 lines but if the opening and closing target are really big then any idea on that?

thanks Corona
# 6  
Old 02-16-2012
If it's too big for awk on your sytem try nawk.
# 7  
Old 02-16-2012
Solution to post #5:
Code:
sed -n '/<target.*UpgradePrimaryBox/,/<\/target>/p' inputfile

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script reg-exp , replace , open and write

Hi All I am a new in scripting language and I would like help for you guys I would like to create a file named constant.h and search into all files *.m in specific directory for a reg-exp @"LBL_]+" exp: @"LBL_75847" , and write those matchs to constant.h if there are not written (no... (15 Replies)
Discussion started by: molwiko
15 Replies

2. Shell Programming and Scripting

perl reg-exp

$var1="LEN"; $VAR2="CODLENTT"; now, var2 contains var1(LEN).How do i check this in perl.... whether one string is a part of another..? if (<logic>) { my operation; } what'd be the logic.. (4 Replies)
Discussion started by: vijay_0209
4 Replies

3. Shell Programming and Scripting

Perl reg exp

Hi, I am using the following piece of code for extracting some data from in between some tags ... $text =~ /<TAG1>(.*)<\/TAG1>.*<TAG2>(.*)<\/TAG2>.*<TAG3>(.*)<\/TAG4>.*<TAG5>(.*)<\/TAG5>/; $tag1=$1; print "\n$tag1"; But I am getting an error like Use of uninitialized value in... (1 Reply)
Discussion started by: King Nothing
1 Replies

4. UNIX for Dummies Questions & Answers

extract a part of a path like (input: /etc/exp/home/bin ====> output: exp)

Hi, I need to make some extraction . with the following input to get the right output. input: /etc/exp/home/bin ====> output: exp and input: aex1234 ===> output: ex Thanks for your help, (4 Replies)
Discussion started by: yeclota
4 Replies

5. Shell Programming and Scripting

reg exp for sed

$ cat file.txt asd <AA>dev <LL>def <RR>sha This works for me: $ sed -r 's/^ .*<LL>def/\t<LL>my/' file.txt asd <AA>dev <LL>my <RR>sha But, this does not work for me: $ sed -r 's/^\s+<LL>def/\t<LL>my/' file.txt asd ... (1 Reply)
Discussion started by: demoprog
1 Replies

6. Shell Programming and Scripting

reg exp question

Hi, Should be a difference between ']]*' and ']+' ? I use them in bash with sed and grep. Thanks (1 Reply)
Discussion started by: ynir
1 Replies

7. Shell Programming and Scripting

usage...sed/awk/reg-exp ..in shell scripting

in shell scripting there is extensive usage of i> regular expression ii>sed iii>awk can anyone tell me the suitable contexts ...i mean which one is suitable for what kind of operation. like the reg-exp and sed seems to be doing the same job..i.e pattern matching (1 Reply)
Discussion started by: mobydick
1 Replies

8. Shell Programming and Scripting

Using reg. exp. variable in AWK??

Any idea please: How to pass a reg. exp. variable to awk call in a shell??? Thank u #!/bin/sh reg_exp=name awk '/reg_exp/{ print; }' $1 (5 Replies)
Discussion started by: andy2000
5 Replies
Login or Register to Ask a Question