ksh to compare alphanumeric values from 2 files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh to compare alphanumeric values from 2 files
# 1  
Old 09-20-2011
ksh to compare alphanumeric values from 2 files

Hi there,

I want to compare 2nd column which are alphanumeric values from each of the 2 files i.e.,lspv_pre.out and lspv_post.out , if found echo some message.

lspv_pre.out

Code:
hdisk0          00c39eaa451144dd                    rootvg          active
hdisk1          00c39eaa45223322                    testvg1        active
hdisk2          00c39eae321733d8                    testvg1        active
hdisk3          00c39eaa121273d8                    testvg1        active
hdisk4          00c39eaa340989e3                    testvg2        active
hdisk5          00c39eaa57821b1a                    testvg2        active
hdisk6          00c39eaa68dd9313                    testvg2        active


lspv_post.out

Code:
hdisk0          00c39eaa451144dd                    rootvg          active
hdisk1          00c39eaa45223322                    None        None
hdisk4          00c39eae321733d8                    None        None
hdisk5          00c39eaa121273d8                    None        None
hdisk6          00c39eaa340989e3                    None        None
hdisk7          00c39eaa57821b1a                    None        None
hdisk9          00c39eaa68dd9313                    None        None

Any help is much appreciated...

Thanks
MBAK

Last edited by radoulov; 09-20-2011 at 05:42 PM.. Reason: Code tags!
# 2  
Old 09-20-2011
Code:
#!/bin/ksh

exec 5<lspv_pre.out
exec 6<lspv_post.out

LINE=0
while true
do
        LINE=$((LINE+1))
        read A1 B1 C1 <&5 || break
        read A2 B2 C2 <&6 || break

        [ "$B1" = "$B2" ] || echo "Line $LINE, $B1 != $B2"
done

exec 5<&-
exec 6<&-

# 3  
Old 09-20-2011
Thanks Corona688 for prompt response..your script compares line by line which is ok but what if the 2nd column in lspv_post.out jumbled up like below...
Code:
hdisk0          00c39eaa451144dd                    rootvg          active
hdisk7          00c39eaa57821b1a                    None        None
hdisk5          00c39eaa121273d8                    None        None
hdisk9          00c39eaa68dd9313                    None        None
hdisk4          00c39eae321733d8                    None        None
hdisk1          00c39eaa45223322                    None        None
hdisk6          00c39eaa340989e3                    None        None


Last edited by Scott; 09-20-2011 at 07:43 PM.. Reason: Code tags, please!
# 4  
Old 09-20-2011
Then it might have been helpful to reflect that in your test data.
Code:
awk 'BEGIN { while(getline <"lspv_pre.out") LINE[$1]=$2 }
{
        if(LINE[$1] != $2) printf("Line %d, %s != %s\n", NR, LINE[$1], $2);
}' < lspv_post.out

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need to compare numbers in alphanumeric string

Hi, I will be having file names like below, 1420SP1.01804 1420SP1.01805D 1420SP1.01805 1420SP1.01806D 1420SP1.01806 1420SP1.01901D 1420SP1.01901 1420SP1.01902D 1420SP1.01902 1420SP1.01903D 1420SP1.01903 1420SP1.01904 1420SP1.01905 From this, I need to list file names which is... (3 Replies)
Discussion started by: Sumanthsv
3 Replies

2. Shell Programming and Scripting

Sort two columns with alphanumeric values horizontally

Hi, I have a file like aa bb dmns|860 dmns|756 ee ff aa bb dmns|310 dmns|260 ee ff aa bb dmns|110 dmns|77 ee ff aa bb dmns|756 dmns|860 ee ff aa bb dmns|110 dmns|77 ee ff aa bb dmns|233 dmns|79 ee ff aa bb dmns|79 dmns|233 ee ff I want to sort the values in column3 and column4... (2 Replies)
Discussion started by: sammy777888
2 Replies

3. Shell Programming and Scripting

Compare values in two different files

Hello, I have output in one file that looks like: AA 3 BB 1 CC 3 DD 6 EE 2 FF 6 And output in another file that looks like: 1 EE 3 CC 2 AA I basically want to be able to match the counts in each file against the correct corresponding initials (and then obviosuly base a command on... (7 Replies)
Discussion started by: Nik44
7 Replies

4. Shell Programming and Scripting

Compare two files column values using awk

Judi # cat File1 judi /export/home 76 judi /usr 83 judi # judi # cat File2 judi /export/home 79 judi /usr 82 judi # if COLUMN3 of File2 is greater that COLUMN3 of File1, then print File2's lines juid /export/home 79 Code tags please (2 Replies)
Discussion started by: judi
2 Replies

5. UNIX for Dummies Questions & Answers

I want to compare to alphanumeric value in a unix shell script.

#!/bin/sh b= SERVER if ; then echo "hostname $a is same" ____________________________ (17 Replies)
Discussion started by: Nsharma3006
17 Replies

6. Shell Programming and Scripting

Compare values in two files. For matching rows print corresponding values from File 1 in File2.

- I have two files (File 1 and File 2) and the contents of the files are mentioned below. - I am trying to compare the values of Column1 of File1 with Column1 of File2. If a match is found, print the corresponding value from Column2 of File1 in Column5 of File2. - I tried to modify and use... (10 Replies)
Discussion started by: Santoshbn
10 Replies

7. Shell Programming and Scripting

Compare to files and export only different values

Hello, I need to compare two files which have the following structure File1: No : 1 Name : George/Brown Value2 : type2 Value3 : type3 Date : Wed Oct 20 11:12:58 2010 Value : yes No : 2 Name : John/Cash Value2 :... (4 Replies)
Discussion started by: @dagio
4 Replies

8. Shell Programming and Scripting

Need to compare values on two CSV files

:( Hello, Having a problem with reading two files using awk/nawk, am new to both them. I need to compare field values between two csv files and arrange for an appropriate output if both the values are equal or not for each feild. $cat File1.csv... (4 Replies)
Discussion started by: pgop
4 Replies

9. Shell Programming and Scripting

Compare values between files

I have two files with same name residing in different directory. Each file has 14 columns. I want to compare column by column for each row. Also, have to take two columns as key identifier;pick a row in File1; retrieve the corresponding row from file2 and then compare the values. Can... (1 Reply)
Discussion started by: Sangtha
1 Replies

10. Shell Programming and Scripting

ksh - test if string contains alphanumeric...

Okay I will let users input spaces as well :) I am having a mental block. I have done a couple of searches but havent found anything that I understand (the likes of :alpha: and awk). Basically I want to give the user an option to enter some text which will go down as a field within a flat... (3 Replies)
Discussion started by: tugger
3 Replies
Login or Register to Ask a Question