The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
file Lookup using awk jerome Sukumar Shell Programming and Scripting 1 08-30-2007 12:28 AM
Lookup with a file pavan_test UNIX for Dummies Questions & Answers 5 07-21-2006 07:57 AM
reverse lookup file problem Westy564 IP Networking 2 01-09-2004 11:55 AM
file lookup gillbates UNIX for Dummies Questions & Answers 6 12-12-2003 11:04 AM
grep multiple text files in folder into 1 text file? coppertone UNIX for Dummies Questions & Answers 7 08-23-2002 11:50 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #8  
Old 10-19-2006
Registered User
 

Join Date: Oct 2006
Location: Bangalore, India
Posts: 41
Hi ripat

u almost read my mind. removing those things will be helpful but not necessary for me. My final objective, which i didnt mention, was to search for pattern 'condition' after retrieving the text and then output the job name which is there after 'condition'.

I tried running the code u gave and this is what its giving

while read str
> do
> sed -n "/-- $str --/, /^$/ {/-- $str --/b;/^$/b;p}" b1
> done<a1
sed: command garbled: /-- ab --/, /^$/ {/-- ab --/b;/^$/b;p}
sed: command garbled: /-- cd --/, /^$/ {/-- cd --/b;/^$/b;p}
sed: command garbled: /-- ef --/, /^$/ {/-- ef --/b;/^$/b;p}

can u explain the command line in a bit of detail...for e.g. what is the b obtion for :- {/-- $str --/b;/^$/b;p} is it for replacing with a blank?

I also ran the awk script. That is not returning anything..just the command prompt.

while read str
do
awk 'BEGIN{FS="\n"; RS="\n\n"; OFS="\n"} /-- ab --/ {for (i = 2; i <= NF; i++) print $i}' b1
done<a1
Reply With Quote
Forum Sponsor
  #9  
Old 10-19-2006
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Quote:
Originally Posted by napolayan
thanks anbu123

ur code is working fine, but i want to clarify my understanding of it.

/\/\*--* $str --*\*\//

this portion i got. u are searching for the string, fine.

,/^ *$/ p

two questions here..pardon my ignorance of this format (i am a newbie after all ), but why the comma? n the ^ *$ will return everything till it encounters a space at the end, right?

n what abt the mystery of there apparently being no newline character after each line of b1?


P.S. thanks to u too ghostdog74, but i am an ignoramus when it comes to python so everything went just like electricity does - Overhead Transmission.
"/\/\*--* $str --*\*\//,/^ *$/ p
Here trying to match from a line with pattern /\/\*--* $str --*\*\// to another line with the pattern /^ *$/.If you want to specify two address then you have to separate it with comma.

/^ *$/
* matches any number or none of the single character that immediately precedes it.So this will match empty line as well as lines with blanks.
Reply With Quote
  #10  
Old 10-19-2006
Registered User
 

Join Date: Oct 2006
Location: Bangalore, India
Posts: 41
Quote:
Originally Posted by anbu23
"/\/\*--* $str --*\*\//,/^ *$/ p
Here trying to match from a line with pattern /\/\*--* $str --*\*\// to another line with the pattern /^ *$/.If you want to specify two address then you have to separate it with comma.

/^ *$/
* matches any number or none of the single character that immediately precedes it.So this will match empty line as well as lines with blanks.
thanks anbu

this funda i hadnt come across in the 2 months that i hv been learning unix. i thought only sed '1,3 p' works. didnt know patterns can also be matched the same way.
Reply With Quote
  #11  
Old 10-20-2006
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Quote:
Originally Posted by napolayan
Hi ripat

u almost read my mind. removing those things will be helpful but not necessary for me. My final objective, which i didnt mention, was to search for pattern 'condition' after retrieving the text and then output the job name which is there after 'condition'.

I tried running the code u gave and this is what its giving

while read str
> do
> sed -n "/-- $str --/, /^$/ {/-- $str --/b;/^$/b;p}" b1
> done<a1
sed: command garbled: /-- ab --/, /^$/ {/-- ab --/b;/^$/b;p}
sed: command garbled: /-- cd --/, /^$/ {/-- cd --/b;/^$/b;p}
sed: command garbled: /-- ef --/, /^$/ {/-- ef --/b;/^$/b;p}

can u explain the command line in a bit of detail...for e.g. what is the b obtion for :- {/-- $str --/b;/^$/b;p} is it for replacing with a blank?

I also ran the awk script. That is not returning anything..just the command prompt.

while read str
do
awk 'BEGIN{FS="\n"; RS="\n\n"; OFS="\n"} /-- ab --/ {for (i = 2; i <= NF; i++) print $i}' b1
done<a1
b is for branching. If label is given control will transfer to that label or else control is transferred to the end of the script.
You can use d to achieve the same result

Code:
while read str
do
      sed  -n "/-- $str --/, /^$/ {/-- $str --/d;/^$/d;p}" b1
done<a1
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:26 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0