Thank you Don. I corrected "cnt[$5]" to "c[5]" and it worked (on bash in OS X 10.6).
---------- Post updated at 02:08 PM ---------- Previous update was at 02:03 PM ----------
Thanks Rudi. That works great. So far I avoided learning awk except for the simplest tasks, because the flow control in snippets I've grabbed here and there is so terse (to me it appears non-existent in your and Don Cragun's solutions). But I've just got hold of Dale Dougherty's book on sed and awk, and I'll be learning how this works now. (Where's the loop for reading the file on the first pass? Where's the conditional print? Etc... I can already see from looking over Dougherty's book that the answers are there, no need to answer.)
Thank you Don. I corrected "cnt[$5]" to "c[5]" and it worked (on bash in OS X 10.6).
---------- Post updated at 02:08 PM ---------- Previous update was at 02:03 PM ----------
Thanks Rudi. That works great. So far I avoided learning awk except for the simplest tasks, because the flow control in snippets I've grabbed here and there is so terse (to me it appears non-existent in your and Don Cragun's solutions). But I've just got hold of Dale Dougherty's book on sed and awk, and I'll be learning how this works now. (Where's the loop for reading the file on the first pass? Where's the conditional print? Etc... I can already see from looking over Dougherty's book that the answers are there, no need to answer.)
Hi uncleMonty,
I apologize for the typo. It has now been corrected in my earlier post. Note that cnt[$5] should have been changed to c[$5] (NOT c[5])!.
The general form of an awk command (as I'm sure you will find in your book (or the [codei]awk[/icode] man page on your system) is:
If the condition is not present, the given action is applied to every input line that gets to that statement. If action and the surrounding braces are not present, a default action of print (which prints the current input line after any modifications to that line's contents applied by any previous statements have been applied) is taken for any line in which condition evaluates to a non-zero, non-empty string value. So, the awk statement:
prints any line for which the count of the number of times the contents of fields 1, 3, 5, and 7 have all all been seen cnt or more times.
Yes, thanks for the description. And I've learned that the loop through the file the first time to build the array of counters is kept separate from the second loop that prints the line, via the `NR==FNR` trick that I read a good account of in the "two-file processing" section of this webpage: [EDIT: I thought I posted this yesterday but apparently I don't have enough "juice" to give a url on this forum. But the helpful webpage I was just consulting can be found on the backreference.org site with the title "idiomatic awk".]
Guys i need an idea for one logic..in shell scripting am struggling with a logic...So the thing is... i need to search for a word in a huge log file and i need to continue to print few more lines from that line and the consecutive line has to end when it finds the line with date..because i know... (1 Reply)
Hi ,
i have a file with data as below.This is same file. But actual file contains to many rows.
i want to search for a string "Field 039 00" and delete that line and previous 3 lines in that file.. Can some body suggested me how can i do using either sed or awk command ?
Field 004... (7 Replies)
Hi All,
I want to read all lines after a perticular string {SET UP VALUES}apprears in the file.
SET UP values contains direcory, number of days and file type.
Step1: Read all lines below SET UP VALUES string.
Step2: If set up values are not present in each record then read from default... (4 Replies)
i need to get least lines of file after last word TEST in file, and send that lines to mail
example of file structure:
TEST 10.10.2010
jdfjdnjfndjfndnfkdk
djfjdnfjkdjkfnjkdfk
jdfjdjfnjdjnfjkdnfjk
TEST 11.10.2010
jdjfnjdnfdkdfjdfjdnk
jdnfjdnjkfndnfjdnfjk
fjdnfjkndnfdfnjdnfjk
TEST... (6 Replies)
Hi Experts,
I have a file which contains some text. i need to print the word next to a given keyword. Please help.
Ex: test.txt
=====================
NEXT HOST
=====================
AEADBAS001
access-list 1 permit xxxxxxxxxxxxxx
ip access-list extended BLA_Outgoing_Filter... (6 Replies)
i have a file containing over 1 million records,and i want to print about 300,000 line containing a some specific words.
file has content.
eg
1,rrt,234
3,fgt,678
4,crf,456
5,cde,drt
6,cfg,123
and i want to print the line with the word fgt,crf
this is just an example,my file is so... (2 Replies)
Hello all, new to unix and have just found the forum.
I think I will be here quite often, and hope that in time i will be able to provide soem help, role on not being a newbie anymore :)
I have a question which iI am hoping someone could help me with.
If i have a file with lines in in thus... (8 Replies)
Hi,
I would like to know how to solve one of my problems using expert unix commands.
I have a file with occasional blank lines;
for example;
dertu
frthu
fghtu
frtty
frtgy
frgtui
frgtu
ghrye
frhutp
frjuf
I need to edit the file so that the file looks like this; (10 Replies)
My sql file xyz_abc.sql in this file there are multiple sql block in this block I need to find the following block
rem Subset Rows (&&tempName.*)
CREATE VIEW &&tempName.* AS
SELECT *
FROM &&tempName.*
WHERE f is not null
and replace with following code
rem Subset Rows... (9 Replies)
i have a file a.txt and following is only one portion.
I want to search <branch value="/dev36/AREA/" include="yes"></branch> present in between
<template_file name="Approve External" path="core/approve/bin" and </template_file>
where the no of lines containing "<branch value= " is increasing ... (2 Replies)