Awk counting lines with field match


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Awk counting lines with field match
# 8  
Old 05-09-2009
wow!!, thanks for giving up your time to do this.

I had python ages ago but unfortunatly i havnt got it any more, well i dont think i do anyway. Cheers for that solution though.

Thanks Devaraj Takhellambam, im now altering it to go in my program so it uses outside variables for st and lt,

I think im going to have to use two awk's as they do different jobs, unless there is a way of piping the ouput from one awk into two different inputs.

Thanks again

p.s. if you get a chance could you explain some of your code plz, im trying to firgure it out to learn from it

When you have getline what is the "-",
and also what does this do
{a[$1]=$0;next} and substr($5,1,2)
Sorry, ive only just started learning unix so i want to learn.

Last edited by fredted40x; 05-10-2009 at 07:19 AM..
# 9  
Old 05-11-2009
Quote:
Originally Posted by fredted40x
wow!!, thanks for giving up your time to do this.

I had python ages ago but unfortunatly i havnt got it any more, well i dont think i do anyway. Cheers for that solution though.

Thanks Devaraj Takhellambam, im now altering it to go in my program so it uses outside variables for st and lt,

I think im going to have to use two awk's as they do different jobs, unless there is a way of piping the ouput from one awk into two different inputs.

Thanks again

p.s. if you get a chance could you explain some of your code plz, im trying to firgure it out to learn from it

When you have getline what is the "-",
and also what does this do
{a[$1]=$0;next} and substr($5,1,2)
Sorry, ive only just started learning unix so i want to learn.
1. Getline with a "-" will take the input from stdin/keyboard.
2. a[$1]=$0 is creating an array name a and the index of the array is $1(first field) and its value is the line of the input file. and "next" will go over and over until all the lines of the first file is loaded into the array.
3. substr($5,1,2) will extract a part of the text of the 5'th field, starting a position 1 and 2 charaters from there.


cheers,
Devaraj Takhellambam
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to match field between two files and use conditions on match

I am trying to look for $2 of file1 (skipping the header) in $2 of file2 (skipping the header) and if they match and the value in $10 is > 30 and $11 is > 49, then print the line from file1 to a output file. If no match is foung the line is not printed. Both the input and output are tab-delimited.... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

awk to match value to a field within +/- value

In the awk below I use $2 of filet to search filea for a match. If the values in $2 are exact match this works great. However, that is not always the case, so I need to perform the search using a range of + or - 2. That is if the value in filea $2 is within + or - 2 of filet $2 then it is matched.... (6 Replies)
Discussion started by: cmccabe
6 Replies

3. Shell Programming and Scripting

awk repeat one field at all lines and modify field repetitions

Hello experts I have a file with paragraphs begining with a keeping date and ending with "END": 20120301 num num John num num A keepnum1 num num kathrin num num A keepnum1 num num kathrin num num B keepnum2 num num Pete num num A keepnum1 num num Jacob num... (2 Replies)
Discussion started by: phaethon
2 Replies

4. Shell Programming and Scripting

Counting lines in a file using awk

I want to count lines of a file using AWK (only) and not in the END part like this awk 'END{print FNR}' because I want to use it. Does anyone know of a way? Thanks a lot. (7 Replies)
Discussion started by: guitarist684
7 Replies

5. Shell Programming and Scripting

counting lines that match pattern

I have a file of 1.3 millions lines. some are with the same word twice on the line, some line have two diffrent words. each line has two words, one in brackets. example: foo (foo) bar (bar) thae (awvd) beladf (vswvw) I am sure this can be done with one line of... (6 Replies)
Discussion started by: robsonde
6 Replies

6. UNIX for Dummies Questions & Answers

awk display the match and 2 lines after the match is found.

Hello, can someone help me how to find a word and 2 lines after it and then send the output to another file. For example, here is myfile1.txt. I want to search for "Error" and 2 lines below it and send it to myfile2.txt I tried with grep -A but it's not supported on my system. I tried with awk,... (4 Replies)
Discussion started by: eurouno
4 Replies

7. Shell Programming and Scripting

AWK: Pattern match between 2 files, then compare a field in file1 as > or < field in file2

First, thanks for the help in previous posts... couldn't have gotten where I am now without it! So here is what I have, I use AWK to match $1 and $2 as 1 string in file1 to $1 and $2 as 1 string in file2. Now I'm wondering if I can extend this AWK command to incorporate the following: If $1... (4 Replies)
Discussion started by: right_coaster
4 Replies

8. Shell Programming and Scripting

counting lines containing two column field values with awk

Hello everybody, I'm trying to count the number of consecutive lines in a text file which have two distinctive column field values. These lines may appear in several line blocks within the file, but I only want a single block to be counted. This was my first approach to tackle the problem (I'm... (6 Replies)
Discussion started by: origamisven
6 Replies

9. Shell Programming and Scripting

Counting lines of code in a directory with awk

I've never toyed with awk, but it seems every time I present an elegant 2- to 8-line script, someone comes back with an awk 1-liner. I just came up with this to count all the lines of source code in a directory. How would I do it in awk? LINES=0 for n in $(wc -l *.cpp *.h | cut -b-7); do ... (2 Replies)
Discussion started by: KenJackson
2 Replies

10. Shell Programming and Scripting

awk - Counting number of similar lines

Hi All I have the input file OMAK_11. OMAK 000002EXCLUDE 1341 OMAK 000002EXCLUDE 1341 OMAK 000002EXCLUDE 1341 OMAK 000003EXCLUDE 1341 OMAK 000003EXCLUDE 1341 OMAK 000003EXCLUDE ... (8 Replies)
Discussion started by: dhanamurthy
8 Replies
Login or Register to Ask a Question