Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AWK Script Problem

Status
Not open for further replies.

dcmedic

Technical User
Jul 23, 2001
5
US
I have an AWK script that prompts the user for a word or phrase in a text file that includes the U.S. Constitution. The awk script can find and print each individual line that ontains the word or phrase. But I also need to print the entire paragraph...which is what I am having problems with.

this works for printing one line:

awk --assignIGNORECASE=1 '{if(/'"$words"'/&&/^Clause/){print $0}' usconst.txt

The paragraph must begin with the word "Clause"

How do I print the entire paragraph?

Kenny
 
awk --assign IGNORECASE=1 --assign WORD="$words" -f PrintClause.awk usconst.txt

PrintClause.awk :

/^Clause/ {
if (Found) {
for (i=1; i<=LineCnt ; i++)
print Line
}
Found = 0
LineCnt = 0
}

$0 ~ WORD {
Found = 1
}

{
Line[++LineCnt] = $0
}
Jean Pierre.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top