LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-02-2007, 08:15 PM   #1
aggressivebloodcell
LQ Newbie
 
Registered: Jun 2007
Posts: 3

Rep: Reputation: 0
awk


I have a couple related questions.

(I would try this right now, but I don't have linux at home)

awk "/Happy/,/Valley/" filex

I know that this will find text between the words Happy and Valley. Will this work with symbols such as <& and &>,and will it invoke every time these symbols are seen?

For example:

<& gdsfdgfdg gfsdgf eref ewrwer
etret fd fgfdg hgh wee hg
&> qwe dg ghgf nmmb jkjh jk gj


sdffsfdfdsf dfsfsd fdsfsff
fdsf fdsf fdsf fdsfd fdsf

<& fgfd thyt gfdgfd hgfhfg hh
&> fdfdsfdsfd fffdsfsdffsfdfs

Also, is there a way to do multiple actions for awk. For example: awk "/<&/,/&>/" -f filname filex. I am trying to first select between markers, and then proceed to begin my script for a word count. I really don't want to do a bunch of boolean expressions in my script. I hope my questions make sense.

Thanks
-abc
 
Old 07-02-2007, 08:43 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Here is what you first command does:
Code:
root@2[play]# more awkfile   ## the input file
the at or if
never done
done
last first more
more
more
the at next last
never more at if more less
last at if

root@2[play]# awk "/never/" awkfile   ##prints all lines containing "never"
never done
never more at if more less

root@2[play]# awk "/never/,/more/" awkfile   ##prints lines from 1st instance of "never"
to last instance of "more"--but NOT the lines containing only more.
never done
done
last first more
never more at if more less

root@2[play]# awk "/more/" awkfile   ##prints all lines containing "more"
last first more
more
more
never more at if more less
From this quick test, I'm, not sure WHAT rule is being followed

Last edited by pixellany; 07-02-2007 at 08:44 PM.
 
Old 07-02-2007, 09:20 PM   #3
card-suse
Member
 
Registered: Dec 2005
Location: Ohio, USA
Distribution: OpenSuSE 10.2
Posts: 74

Rep: Reputation: 15
Quote:
Originally Posted by aggressivebloodcell
Also, is there a way to do multiple actions for awk. For example: awk "/<&/,/&>/" -f filname filex. I am trying to first select between markers, and then proceed to begin my script for a word count. I really don't want to do a bunch of boolean expressions in my script. I hope my questions make sense.
I'm not sure what you mean by "multiple actions". You can do as many actions as you like with an awk script. I guess I'm trying to understand what you're really trying to do. Is it simply a word count between some tags?
 
Old 07-03-2007, 12:51 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
I found it---
From the Grymoire Awk tutorial:
Quote:
/start/,/stop/ {print}

This form defines, in one line, the condition to turn the action on, and the condition to turn the action off. That is, when a line containing "start" is seen, it is printed. Every line afterwards is also printed, until a line containing "stop" is seen. This one is also printed, but the line after, and all following lines, are not printed. This triggering on and off can be repeated many times.
Referring to my earlier example, the start and stop can be on the same line, or several lines apart.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using awk vkmgeek Linux - General 2 03-14-2007 08:07 AM
awk kalyanofb Programming 4 02-19-2007 02:55 AM
Help with awk kshkid Programming 1 12-22-2006 06:59 AM
Do you know awk? Vitalka Programming 5 12-01-2006 11:42 PM
using awk meniscus Linux - Newbie 6 10-05-2006 01:39 PM


All times are GMT -5. The time now is 06:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration