- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: help with awk
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2004 08:08 AM
10-12-2004 08:08 AM
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2004 08:22 AM
10-12-2004 08:22 AM
Re: help with awk
I would do this in two parts. First gleen out the text you want via the start/stop parameters to a temp file. Then awk the temp file contents as necessary to achive the desired output.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2004 08:27 AM
10-12-2004 08:27 AM
Re: help with awk
file:
Start
id fname lname
-- ----- -----
1 John Wayne
2 Bill Smith
Stop
Start
id fname lname
-- ----- -----
Stop
Start
id fname lname
-- ----- -----
1 Mark Williams
Stop
I don't want the 'chunk' with no names in it.
awk:
/Start/,/Stop/ {print}
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2004 08:29 AM
10-12-2004 08:29 AM
Re: help with awk
# cat > testfile
hai test
start
testfile
okei content
itrc forum
stop
over
# awk '/start/,/stop/ { print $0 }' testfile
start
testfile
okei content
itrc forum
stop
If you want to get only contents inside limit exactly then,
# awk '/start/,/stop/ { if ( $0 != "start" && $0 != "stop" ) print $0 }' testfile
testfile
okei content
itrc forum
It will give you the way there.
HTH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2004 08:43 AM
10-12-2004 08:43 AM
Re: help with awk
awk '$1 ~ /[0-9]*/ {print $0;}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2004 08:54 AM
10-12-2004 08:54 AM
Re: help with awk
Start
id fname lname
-- ----- -----
1 John Wayne
2 Bill Smith
Stop
Start
id fname lname
-- ----- -----
Stop
Start
id fname lname
-- ----- -----
1 Mark Williams
Stop
I need the output to look like this:
id fname lname
-- ----- -----
1 John Wayne
2 Bill Smith
id fname lname
-- ----- -----
1 Mark Williams
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2004 09:15 AM
10-12-2004 09:15 AM
Re: help with awk
/start/ {
# set print flag, don't print this line
flag=1;}
/stop/ {
#unset print flag, don't print this line
flag=0;
#print blank line
print "";}
{print $0;}' yourFile
a uncommented version
awk '/start/{flag=1;}
/stop/ {flag=0;print "";}
{print $0;}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2004 09:28 AM
10-12-2004 09:28 AM
Re: help with awk
this {print $0;}'
should have been
{if ( flag == 1 ) print $0;}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2004 09:29 AM
10-12-2004 09:29 AM
Re: help with awk
Start
id fname lname
-- ----- -----
1 John Wayne
2 Bill Smith
Stop
Start
id fname lname
-- ----- -----
Stop
Start
id fname lname
-- ----- -----
1 Mark Williams
Stop
Same as before but with a space before the Stop... Is there any way awk can process the 'chunk' one at a time... I know that if there are no names in the list it returns 4 rows... the Start and Stop, the header and the dashes... I can't check if the NR is 4 just for each search?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2004 09:32 AM
10-12-2004 09:32 AM
Re: help with awk
needs to be before the /start/
awk '/start/{flag=1;}
/stop/ {flag=0;print "";}
{print $0;}'
should be
awk 'BEGIN {flag=0)
{if ( flag == 1 ) print $0;}
/start/ {flag = 1;}
/stop/ {flag = 0;print "";}'
oh boy what was i thinking before
better go home before i ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2004 09:43 AM
10-12-2004 09:43 AM
Re: help with awk
>cat dummy3.out
Start
id fname lname
-- ----- -----
1 John Wayne
2 Bill Smith
Stop
Start
id fname lname
-- ----- -----
Stop
Start
id fname lname
-- ----- -----
1 Mark Williams
Stop
>cat dummy3.awk
BEGIN {flag=0}
{if ( flag == 1 ) print $0;}
/Start/ {flag = 1;}
/Stop/ {flag = 0;print "";}
>awk -f dummy3.awk dummy3.out
id fname lname
-- ----- -----
1 John Wayne
2 Bill Smith
Stop
id fname lname
-- ----- -----
Stop
id fname lname
-- ----- -----
1 Mark Williams
Stop
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2004 09:49 AM
10-12-2004 09:49 AM
Re: help with awk
{if ( flag == 1 ) print $0;}
to
{if ( flag == 1 && $1 !~ "stop" ) print $0;)
sorry for all the incorrect scripts
should have tested before typing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2004 01:50 PM
10-12-2004 01:50 PM
Re: help with awk
Something like this?
awk 'BEGIN{xx=0}/Start/{x=1}/Stop/{if (xx>3){for(i=0;i
Store each line seen in array l[], incrementing index by x which may be 0 or 1.
Only after seeing start, set array index increment x to 1
When seeing stop, print all array lines if there are enough.
When seeing stop clear increment.
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2004 02:53 PM
10-12-2004 02:53 PM
Re: help with awk
INPUT DATA
$ cat infile
Start
id fname lname
-- ----- -----
1 John Wayne
102982 Bill Smit
Stop
Start
id fname lname
-- ----- -----
Stop
Start
id fname lname
-- ----- -----
1 Mark Williams
Stop
AWK CODE:
$ awk '/^[[:digit:]]+ /' infile
RESULT:
1 John Wayne
102982 Bill Smith
1 Mark Williams
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2004 02:59 PM
10-12-2004 02:59 PM
Re: help with awk
awk ' /Start/,/Stop/ { if(match($0,/^[[:digit:]]+ /)) print $0 }' infile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2004 04:30 PM
10-12-2004 04:30 PM
SolutionLooking back my example printed too much (I misread an other example to mean that the start and stop line would be needed.
Here is an other try:
awk '/Start/{x=1;y=0}/Stop/{if (y>3){l[y]="\n"; while(i++
This outputs:
id fname lname
-- ----- -----
1 John Wayne
2 Bill Smith
id fname lname
-- ----- -----
1 Mark Williams