Sponsored Content
Top Forums Shell Programming and Scripting Looking for AWK Solution for column comparison in a single file Post 302424512 by softwarekids23 on Tuesday 25th of May 2010 12:24:49 PM
Old 05-25-2010
Looking for AWK Solution for column comparison in a single file

- I am looking for different kind of awk solution which I don't think is mentioned before in these forums.

Number of rows in the file are fixed
Their are two columns in file1.txt

1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10


I am looking for 3 scenarios.
- If column 1 and 2 are same then generate PASS in Third Column (I have figured out this).
- If a number in Column 1 is less than column 2 (which means a number is missing in column 2)then
--generate FAIL in Column 3.
-- Move the number in Column 2 of that row to next row. Move all the numbers in column 2 after that number in thier next rows.
-- generate MISSING In Column 2.

-- Below is the example

file1.txt
1 1
2 3
3 4
4 5
5 7
6 8
7 9
8 10
9
10

As per second scenario what I want is

file1.txt
1 1 PASS
2 MISSING FAIL
3 3 PASS
4 4 PASS
5 5 PASS
6 MISSING FAIL
7 7 PASS
8 8 PASS
9 9 PASS
10 10 PASS

- If a number in Column 1 is greater than column 2 (which means a number is missing in column 1)then
--generate FAIL in Column 3.
-- Move the number in Column 1 of that row to next row. Move all the numbers in column 1 after that row in their next rows.
-- generate MISSING in Column 1.
-- Below is the example

file1.txt
1 1
3 2
4 3
5 4
7 5
8 6
9 7
10 8
9
10

As per third scenario what I want is

file2.txt
1 1 PASS
MISSING 2 FAIL
3 3 PASS
4 4 PASS
5 5 PASS
MISSING 6 FAIL
7 7 PASS
8 8 PASS
9 9 PASS
10 10 PASS


- I have figured out PASS FAIL logic which is basically comparison between 2 columns. But I am not able to figure out moving rows logic.
- Any help for this is really appreciated.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Single column to multiple columns in awk

Hi - I'm new to the awk programming language. I'm trying to print a single column of data to several columns, and I found an article on iTWorld.com (ITworld.com - Printing in columns). It looks like the mkCols2 script is very close to what I need to do, but it looks like the end of the code... (2 Replies)
Discussion started by: astroDave
2 Replies

2. UNIX for Advanced & Expert Users

Solution for the Massive Comparison Operation

Hi We have 50 million records in mainframes DB2. We have a requirement to Record the Change Data Capture(CDC) records. i.e New Records or Updated Records that were added into the DB2. Unfortunately we dont have any column indicators to give the details of the changes made to the records. ... (8 Replies)
Discussion started by: raghav288
8 Replies

3. Shell Programming and Scripting

grep/awk on a single column in a for loop

Hi I'm trying to loop through a small list of id's and then pull out a few columns if the id matches that found in column 2 of the larger file. I managed to get one command to work awk -F " " '{if ($2 == '154080196') print $2,$3,$4}' tst.txt | less However, when I try it in a for loop I... (3 Replies)
Discussion started by: flotsam
3 Replies

4. Shell Programming and Scripting

column value comparison in a file

Hi, Can any one help with my below requirement. i need to compare each line by line and in each line i have to compare some columns values with previous line column values in perl script. Can any one help me........! its very urgent. Thanks (3 Replies)
Discussion started by: jam_prasanna
3 Replies

5. Shell Programming and Scripting

awk column comparison big file

Hi all, I would like to compare a column in one file to a column in another file and when there is a match it prints the first column and the corresponding second column. Example File1 ABA ABC ABE ABF File 2 ABA 123 ABB 124 ABD 125 ABC 126 So what I would like printed to a... (6 Replies)
Discussion started by: pcg
6 Replies

6. Shell Programming and Scripting

Subtracting each row from the first row in a single column file using awk

Hi Friends, I have a single column data like below. 1 2 3 4 5 I need the output like below. 0 1 2 3 4 where each row (including first row) subtracting from first row and the result should print below like the way shown in output file. Thanks Sid (11 Replies)
Discussion started by: ks_reddy
11 Replies

7. UNIX for Dummies Questions & Answers

awk solution to duplicate lines based on column

Hi experts, I have a tab-delimited file with one column containing values separated by a comma. I wish to duplicate the entire line for every value in that comma-delimited field. For example: $cat file 4444 4444 4444 4444 9990 2222,7777 6666 2222 ... (3 Replies)
Discussion started by: torchij
3 Replies

8. Shell Programming and Scripting

Range Comparison Of Column Value in File1 with Other File

Hi, I have a file1 whose 17th column needs to be checked if it exists in between the values of column 2 & column 3 as mentioned in another file2. Output of the matched value to be put in separate file 3 & 4. File1: ... (10 Replies)
Discussion started by: siramitsharma
10 Replies

9. Shell Programming and Scripting

Paste 2 single column files to a single file

Hi, I have 2 csv/txt files with single columns. I am trying to merge them using paste, but its not working.. output3.csv: flowerbomb everlon-jewelry sofft steve-madden dolce-gabbana-watchoutput2.csv: http://www1.abc.com/cms/slp/2/Flowerbomb http://www1.abc.com/cms/slp/2/Everlon-Jewelry... (5 Replies)
Discussion started by: ajayakunuri
5 Replies

10. Shell Programming and Scripting

Solution for replacement of 4th column with 3rd column in a file using awk/sed preserving delimters

input "A","B","C,D","E","F" "S","T","U,V","W","X" "AA","BB","CC,DD","EEEE","FFF" required output: "A","B","C,D","C,D","F" "S", T","U,V","U,V","X" "AA","BB","CC,DD","CC,DD","FFF" tried using awk but double quotes not preserving for every field. any help to solve this is much... (5 Replies)
Discussion started by: khblts
5 Replies
COLRM(1)						    BSD General Commands Manual 						  COLRM(1)

NAME
colrm -- remove columns from a file SYNOPSIS
colrm [start [stop]] DESCRIPTION
The colrm utility removes selected columns from the lines of a file. A column is defined as a single character in a line. Input is read from the standard input. Output is written to the standard output. If only the start column is specified, columns numbered less than the start column will be written. If both start and stop columns are spec- ified, columns numbered less than the start column or greater than the stop column will be written. Column numbering starts with one, not zero. Tab characters increment the column count to the next multiple of eight. Backspace characters decrement the column count by one. ENVIRONMENT
The LANG, LC_ALL and LC_CTYPE environment variables affect the execution of colrm as described in environ(7). EXIT STATUS
The colrm utility exits 0 on success, and >0 if an error occurs. SEE ALSO
awk(1), column(1), cut(1), paste(1) HISTORY
The colrm command appeared in 3.0BSD. BSD
August 4, 2004 BSD
All times are GMT -4. The time now is 09:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy