![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Displaying specific lines in a file. | MaestroRage | UNIX for Dummies Questions & Answers | 3 | 02-05-2008 04:57 PM |
| Search File for Specific Words | mevasquez | UNIX for Dummies Questions & Answers | 2 | 12-04-2007 04:31 PM |
| how to remove specific lines from a file | bluemoon1 | Shell Programming and Scripting | 17 | 10-07-2007 10:40 PM |
| How do you specific lines in a file? | hedgehog001 | UNIX for Dummies Questions & Answers | 2 | 08-23-2005 12:04 AM |
| extract specific lines from file | apalex | UNIX for Dummies Questions & Answers | 2 | 05-15-2001 09:57 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Ignore some lines with specific words from file comparison
Hi all,
I need help in doing this scenario. I have two files with multiple lines. I want to compare these two files but ignoring the lines which have words like Tran, Loc, Addr, Charge. Also if i have a word Credit in line, i want to tokenize (i.e string after character "[" ) that line and compare a substring of it. File looks like Record 1 Tran@1050e1f[ airbillNbr=1324576 origLocInfo=Loc@1c29ab2[ locId=923 state=FL locCntry=US postal=32817 locNbr=456 locCurr=CAD lglEntity=E ] destLocInfo=Loc@337838[ locId=298 state=FL locCntry=US postal=32845 locNbr=456 locCurr=CAD lglEntity=E ] shpDt=Tue Jan 08 00:00:00 EST 2008 shprAddrInfo=Addr@18558d2[ acctNbr=123456789 name=Peyton Manning company=Giants address1=Sports Nation address2= city=New York state=NY country=US postal=76543 ] Charge@19c26f5[ code=305 crdtCard=Credit@15eb0a[creditCardTypeCode=M,creditCardExpDate=Sat Feb 28 00:00:00 EST 2009] Any help is appreciated. Thanks, Jak |
|
||||
|
You could use the 'grep -v word ' or 'nawk '$0 !~ /word/' to filter files, redirect output into another files, and after complete filtering, compare files.
That is for word Tran and file fl1 you would use comands: grep -v Tran fl1 > fltr_fl or nawk '$0 !~ /Tran/' fl1 > fltr_fl For "tokenize" I would use the nawk -F[ ' {if ($0 ~ "Credit") { sub($1,"",$0);} print }' fl1 (should be remuwed else first '[' after that, maybe someone else will help on that) I would put filtering commands in script and on end of that run the diff on filtered files. Also the filtering the lines with worlds I would do in : for wrd in ...all words...; do .. done So, it would be this way: Code:
words="Tran Loc Addr Charge"
for wrd im $words ; do
nawk -v chk=#wrd '$0 !~ chk' in_fl >tmp;
cp tmp in_fl;
done
|
|
||||
|
Thanks for your help!
Jak |
| Sponsored Links | ||
|
|