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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic use of awk 1

Status
Not open for further replies.

unmaxpine

Technical User
Jul 26, 2007
14
0
0
CH
Hello,

I don't have any experience in shell programing.

I have to make a small but easy report from a html file in ksh.

I have a file called betrieb.html.

What I have to do is to grep for a pattern an the print the finded line + 3 lines. Is there anyone know how to do that ?

I print the line with akw with this, but I don't know how to print the next 3 lines (could not have more than 1 line found by the regular expression):

awk '/Report/' betrieb.html

Thanks for your help !
 
Hi

If you do not "speek" [tt]awk[/tt] then why not just stay with [tt]grep[/tt] ? Assuming your [tt]grep[/tt] implementation has -A option :
Code:
grep -A 3 Report betrieb.html

Feherke.
 
Thanks for your answers

In my AIX version the grep command doesn't have the -A option.

But looks good for the awk.

Thanks
 
One more question about this awk:

How does can I do to protect the ' special carcter in the regular expression ?

In my file, I have a line like this:

Rapport d'en

and in the regular expression, the ' is not accepted so I try to protect with \, but not accepted by awk:

Code:
awk '/Report d'en/{for(i=0;i<=3;i++){print;getline}}' betrieb.html

Code:
awk '/Report d\'envoi/{for(i=0;i<=3;i++){print;getline}}' betrieb.html

I found in the awk documentation that \ is used to protect special caracter, so I don't why it doesn't works.

Thanks for your help
 
Hi

This is not [tt]awk[/tt] question. Quoting the strings in the command line is the shell's service.
Code:
awk '/Report d[red]'"'"'[/red]en/{for(i=0;i<=3;i++){print;getline}}' betrieb.html

[gray]# or[/gray]

awk [red]"[/red]/Report d'en/{for(i=0;i<=3;i++){print;getline}}[red]"[/red] betrieb.html

Feherke.
 
What about this ?
Code:
awk "/Report d'en/{for(i=0;i<=3;i++){print;getline}}" betrieb.html

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks looks good.

But I don't see any example in the documentation where we use the
 
This is a shell issue, not an awk one.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top