Compare two strings, and print lines containing mismatches


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare two strings, and print lines containing mismatches
# 1  
Old 07-06-2009
Bug Compare two strings, and print lines containing mismatches

pls help me on this... and im really sorry because i really don't know where to start here...

FILE1

ABC DEF 10 2
DEF GHI 11 3
GHI JKL 12 5
JKL MNO 13 7
MNO PQR 14 5


requirements:
1. The third string should only be 10 or 12
2. The fourth string should only be 2 or 3
3. Prinnt lines that contains mismatches.

RESULTING FILE:
DEF GHI 11 3
GHI JKL 12 5
JKL MNO 13 7
MNO PQR 14 5

can anyone pls help me! thanks in advance!
# 2  
Old 07-07-2009
Code:
 
while read record
do
a=`echo $record | cut -d " " -f3`
b=`echo $record | cut -d " " -f4`
if test  $a -eq 10 -o  $a -eq 12
then
if test $b -ne 2 -a $b -ne 3
then
echo $record >>outfile
fi
else
echo $record >>outfile
fi
done<infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print lines between strings like *0123456*

I have a text file contains *02638650* SAMBO 1 Spouse SAMBO FELIX *01591453* MADUAGUGBUO 4 Child3 MADUAGUGBUO JOY *01488523* ANYIAM 1 Spouse ANYIAM FRANCA 2 Child1 ANYIAM GRACE *01647769* EGWUTUOHA 0 Principal ... (6 Replies)
Discussion started by: ktsis
6 Replies

2. Shell Programming and Scripting

Print only lines where fields concatenated match strings

Hello everyone, Maybe somebody could help me with an awk script. I have this input (field separator is comma ","): 547894982,M|N|J,U|Q|P,98,101,0,1,1 234900027,M|N|J,U|Q|P,98,101,0,1,1 234900023,M|N|J,U|Q|P,98,54,3,1,1 234900028,M|H|J,S|Q|P,98,101,0,1,1 234900030,M|N|J,U|F|P,98,101,0,1,1... (2 Replies)
Discussion started by: Ophiuchus
2 Replies

3. Shell Programming and Scripting

Print lines between two strings multiple occurencies (with sed, awk, or grep)

Hello, I can extract lines in a file, between two strings but only one time. If there are multiple occurencies, my command show only one block. Example, monfichier.txt contains : debut_sect texte L1 texte L2 texte L3 texte L4 fin_sect donnees inutiles 1 donnees inutiles 2 ... (8 Replies)
Discussion started by: theclem35
8 Replies

4. Shell Programming and Scripting

Compare last 90 logs and print repeating lines with >20

*log files are in date order sample logs... ciscoresets_20120314 ciscoresets_20120313 ciscoresets_20120312 ciscoresets_20120311 ciscoresets_20120310 cat ciscoresets_20120314 SYDGRE04,10,9 SYDGRE04,10,10 SYDGRE04,10,11 SYDGRE04,10,12 SYDGRE04,10,13 SYDGRE04,10,14 SYDGRE04,10,15... (2 Replies)
Discussion started by: slashbash
2 Replies

5. Shell Programming and Scripting

compare & print lines with 2 requirements

1.compare 90 logs >20 print off with correct figure 2.compare latest log i.e ciscoresets_20120314 against all records not just the 90 (as above) and any lines not matching print as: NEW:SYDGRE04,10,9 1 (note this number could be 2 or whatever not necessary 1 it could be 2,3 or even 10... (2 Replies)
Discussion started by: slashbash
2 Replies

6. Shell Programming and Scripting

Compare one files with strings from another + remove lines

Have two files and want to compare the content of file1 with file2. When matched remove the line. awk 'NR==FNR {b; next} !(b in $0)' file1 file2file1 1. if match 2. removefile2 1. this line has to be removed if match 2. this line has a match, remove 3. this line has no match, no removingThe... (3 Replies)
Discussion started by: sdf
3 Replies

7. Shell Programming and Scripting

Compare strings between 2 arrays and print number in AWK

Hi to everyone, Please some help over here. Hi have array a with 6 elements and array b with 3 elements as shown inside BEGIN{} statement. I need help to get the correct sintax (the part in red) to compare if string from array b is in array a and print the number related for each match.... (3 Replies)
Discussion started by: Ophiuchus
3 Replies

8. Shell Programming and Scripting

Compare two files and print the two lines with difference

I have two files like this: #FILE 1 ABCD 4322 26485 JMTJ 5311 97248 XMPJ 4321 58978 #FILE 2 ABCD 4321 26485 JMTJ 5311 97248 XMPJ 4321 68978 What to do: Compare the two files and find those lines that doesn't match. And have a new file like this: #FILE 3 "from file 1" ABCD 4322 26485... (11 Replies)
Discussion started by: kingpeejay
11 Replies

9. Shell Programming and Scripting

Print all the lines between 2 specified strings

Hi All, I have a file in which i want to print all the lines between 2 defined strings. Ex- I have file with data as follows STEP1:- ----- has some 20 -30 lines of data STEP2:- ----- has some 20 -30 lines of data So i want to print those lines between STEP1 & STEP2. (line including STEP1)... (7 Replies)
Discussion started by: digitalrg
7 Replies

10. Shell Programming and Scripting

How to print only lines in between two strings using awk

Hi, I want to print only lines in between two strings and not the strings using awk. Eg: OUTPUT top 2 bottom 1 left 0 right 0 page 66 END I want to print into a new file only top 2 bottom 1 left 0... (4 Replies)
Discussion started by: jisha
4 Replies
Login or Register to Ask a Question