Sponsored Content
Top Forums Shell Programming and Scripting counting lines containing two column field values with awk Post 302532870 by origamisven on Wednesday 22nd of June 2011 09:12:47 AM
Old 06-22-2011
@panyam: yes, basically

@yazu: thanks, this will probably do it!

I have problems adapting your solution to my problem though. What does this part do?

{ s = s $0 "\n"; getline }

In fact I need to apply it to files like this, where the atoms of several molecules SOL, GLN, etc need to be counted...

 
(...)
ATOM 55772 OW SOL 5362 104.470 140.450 35.110 1.00 0.00
ATOM 55773 HW1 SOL 5362 105.040 141.040 34.530 1.00 0.00
ATOM 55774 HW2 SOL 5362 103.620 140.230 34.630 1.00 0.00
ATOM 55775 OW SOL 5363 47.240 47.300 89.850 1.00 0.00
ATOM 55776 HW1 SOL 5363 46.450 47.900 90.020 1.00 0.00
ATOM 55777 HW2 SOL 5363 46.930 46.410 89.530 1.00 0.00
ATOM 55778 OW SOL 5364 122.910 41.340 72.190 1.00 0.00
ATOM 55779 HW1 SOL 5364 122.410 41.120 71.360 1.00 0.00
ATOM 55780 HW2 SOL 5364 123.530 42.110 72.010 1.00 0.00
ATOM 55781 OW SOL 5365 121.590 102.910 60.970 1.00 0.00
ATOM 55782 HW1 SOL 5365 120.940 102.300 60.520 1.00 0.00
ATOM 55783 HW2 SOL 5365 121.150 103.770 61.190 1.00 0.00
ATOM 55757 NE2 GLN 5358 83.370 21.490 106.870 1.00 0.00
ATOM 55758 1HE2 GLN 5358 83.890 22.060 107.530 1.00 0.00
ATOM 55759 2HE2 GLN 5358 83.280 20.500 107.080 1.00 0.00
ATOM 55760 C GLN 5358 84.800 25.100 108.100 1.00 0.00
ATOM 55761 O1 GLN 5358 84.860 26.360 108.290 1.00 0.00
ATOM 55762 O2 GLN 5358 85.820 24.380 107.860 1.00 0.00
ATOM 55763 OW SOL 5359 73.720 119.460 110.240 1.00 0.00
ATOM 55764 HW1 SOL 5359 73.060 119.910 110.850 1.00 0.00
ATOM 55765 HW2 SOL 5359 73.240 119.130 109.430 1.00 0.00
ATOM 55766 OW SOL 5365 27.480 87.690 57.920 1.00 0.00
ATOM 55767 HW1 SOL 5365 26.550 87.980 57.690 1.00 0.00
ATOM 55768 HW2 SOL 5365 28.130 88.360 57.580 1.00 0.00
ATOM 55769 OW SOL 5364 78.820 91.080 70.170 1.00 0.00
ATOM 55770 HW1 SOL 5364 78.180 90.310 70.120 1.00 0.00
ATOM 55771 HW2 SOL 5364 78.360 91.870 70.560 1.00 0.00
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help with switching field/column values

Hi all, I need some help on switching field/column values. For example I have a file name data.txt which contains: a b a b a b and I want to switch a and b and save it to the same file. the file data.txt then will have: b a b a b a The problem is, well, I know how to... (7 Replies)
Discussion started by: sonyd8
7 Replies

2. UNIX for Dummies Questions & Answers

Awk counting lines with field match

Hi, Im trying to create a script that reads throught every line in a file and then counts how many lines there with a certain field that matches a input, and also ausing another awk it has to do the same as the above but to then use sort anduniq to get rid of all the unique lines with another... (8 Replies)
Discussion started by: fredted40x
8 Replies

3. Shell Programming and Scripting

Transpose field names from column headers to values in one column

Hi All, I'm looking for a script which can transpose field names from column headers to values in one column. for example, the input is: IDa;IDb;IDc;PARAM1;PARAM2;PARAM3; a;b;c;p1val;p2val;p3val; d;e;f;p4val;p5val;p6val; g;h;i;p7val;p8val;p9val; into the output like this: ... (6 Replies)
Discussion started by: popesk
6 Replies

4. Shell Programming and Scripting

How to compare the values of a column in awk in a same file and consecutive lines..

I would like to compare the values of 2nd column of consecutive lines of same file in such a way so that if the difference between first value and second value is more than 100 it should print complete line else ignore line. Input File ========== PDB 2500 RTDB 123 RTDB-EAGLE 122 VSCCP 2565... (4 Replies)
Discussion started by: manuswami
4 Replies

5. UNIX for Dummies Questions & Answers

awk to sum column field from duplicate row/lines

Hello, I am new to Linux environment , I working on Linux script which should send auto email based on the specific condition from log file. Below is the sample log file Name m/c usage abc xxx 10 abc xxx 20 abc xxx 5 xyz ... (6 Replies)
Discussion started by: asjaiswal
6 Replies

6. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

7. Shell Programming and Scripting

[Solved] Counting The Number of Lines Between Values with Multiple Variables

Hey everyone, I have a bunch of lines with values in field 4 that I am interested in. If these values are between 1 and 3 I want it to count all these values to all be counted together and then have the computer print out LOW and the number of lines with those values in between 1 and 3,... (2 Replies)
Discussion started by: VagabondGold
2 Replies

8. Shell Programming and Scripting

Awk: print lines with one of multiple pattern in the same field (column)

Hi all, I am new to using awk and am quickly discovering what a powerful pattern-recognition tool it is. However, I have what seems like a fairly basic task that I just can't figure out how to perform in one line. I want awk to find and print all the lines in which one of multiple patterns (e.g.... (8 Replies)
Discussion started by: elgo4
8 Replies

9. Shell Programming and Scripting

awk to filter out lines containing unique values in a specified column

Hi, I have multiple files that each contain four columns of strings: File1: Code: 123 abc gfh 273 456 ddff jfh 837 789 ghi u4u 395 File2: Code: 123 abc dd fu 456 def 457 nd 891 384 djh 783 I want to compare the strings in Column 1 of File 1 with each other file and Print in... (3 Replies)
Discussion started by: owwow14
3 Replies

10. Shell Programming and Scripting

Sum column values matching other field

this is part of a KT i am going thru. i am writing a script in bash shell, linux where i have 2 columns where 1st signifies the nth hour like 00, 01, 02...23 and 2nd the file size. sample data attached. Desired output is 3 columns which will give the nth hour, number of entries in nth hour and... (3 Replies)
Discussion started by: alpha_1
3 Replies
COMM(1) 						    BSD General Commands Manual 						   COMM(1)

NAME
comm -- select or reject lines common to two files SYNOPSIS
comm [-123i] file1 file2 DESCRIPTION
The comm utility reads file1 and file2, which should be sorted lexically, and produces three text columns as output: lines only in file1; lines only in file2; and lines in both files. The filename ``-'' means the standard input. The following options are available: -1 Suppress printing of column 1. -2 Suppress printing of column 2. -3 Suppress printing of column 3. -i Case insensitive comparison of lines. Each column will have a number of tab characters prepended to it equal to the number of lower numbered columns that are being printed. For example, if column number two is being suppressed, lines printed in column number one will not have any tabs preceding them, and lines printed in column number three will have one. The comm utility assumes that the files are lexically sorted; all characters participate in line comparisons. DIAGNOSTICS
The comm utility exits 0 on success, and >0 if an error occurs. SEE ALSO
cmp(1), diff(1), sort(1), uniq(1) STANDARDS
The comm utility conforms to IEEE Std 1003.2-1992 (``POSIX.2''). HISTORY
A comm command appeared in Version 4 AT&T UNIX. BSD
June 6, 1993 BSD
All times are GMT -4. The time now is 02:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy