Ignore some lines with specific words from file comparison


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ignore some lines with specific words from file comparison
# 1  
Old 03-10-2008
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
# 2  
Old 03-10-2008
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

# 3  
Old 03-13-2008
Thanks for your help!
Jak
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Ignore all lines except the --- dash line in a text file.

How do you write a script to ignore all lines except the --- dash lines and then remove --- dashes from the data in a text file? Also how do you separate data in a text file with a tab (for example, column1 (software) and column2 (date) ) ? Here is my scripts : I am getting errors in... (3 Replies)
Discussion started by: dellanicholson
3 Replies

2. Shell Programming and Scripting

how to print specific lines or words

Hi, Please have a look on below records. STG_HCM_STATE_DIS_TAX_TBL.1207.Xfm: The value of the row is: EMPLID = 220677 COMPANY = 919 BALANCE_ID = 0 BALANCE_YEAR = 2012 STG_HCM_STATE_DIS_TAX_TBL.1207.Xfm: ORA-00001: unique constraint (SYSADM.PS_TAX_BALANCE) violated ... (4 Replies)
Discussion started by: Sachin Lakka
4 Replies

3. UNIX for Dummies Questions & Answers

Extract lines with specific words with addition 2 lines before and after

Dear all, Greetings. I would like to ask for your help to extract lines with specific words in addition 2 lines before and after these lines by using awk or sed. For example, the input file is: 1 ak1 abc1.0 1 ak2 abc1.0 1 ak3 abc1.0 1 ak4 abc1.0 1 ak5 abc1.1 1 ak6 abc1.1 1 ak7... (7 Replies)
Discussion started by: Amanda Low
7 Replies

4. Shell Programming and Scripting

How to ignore single or multiple lines between /* and */ while reading from a file in unix?

I have a file proc.txt: if @debug = 1 then message 'Start Processing ', @procname, dateformat(now(*), 'hh:mm:ss'), @julian type info to client; end if; /* execute immediate with quotes 'insert into sys_suppdata (property, value, key_name) location ''' || @supp_server || '.' ||... (5 Replies)
Discussion started by: kidncute
5 Replies

5. UNIX Desktop Questions & Answers

Display a specific words from a multiple lines

well, i am so not familiar with this kind of things but i am gonna explain extactly what i am looking for so hopfully someone can figure it out :) i have a command that shows memory usage besides the process name, for example(the command output): 500 kb process_1 600 kb process_2 700 kb... (4 Replies)
Discussion started by: Portabello
4 Replies

6. UNIX and Linux Applications

Reading a file for specific words

Hi I have a script where the user calls it with arguments like so: ./import.sh -s DNSNAME -d DBNAME I want to check that the database entered is valid by going through a passwd.ds file and checking if the database exists there. If it doesn't, the I need to send a message to my log... (4 Replies)
Discussion started by: ladyAnne
4 Replies

7. Shell Programming and Scripting

Keep lines with specific words up in an order

I hava a file with following data: number|CREDIT_ID|NULL date|SYS_CREATION_DATE|NULL varchar2|GGS_COMMIT_CHAR|NULL varchar2|GGS_OP_TYPE|NULL number|GGS_SCN|NULL| number|GGS_LOG_SEQ|NULL number|GGS_LOG_POS|NULL number|GGS_ORACREC_SCN|NULL varchar2|BATCH_ID|NULL char|GGS_IMAGE_TYPE|NULL ... (6 Replies)
Discussion started by: kolesunil
6 Replies

8. Shell Programming and Scripting

To fetch specific words from a file

Hi All, I have a file like this,(This is a sql output file) cat query_file 200000029 12345 10001 0.2 0 I want to fetch the values 200000029,10001,0.2 .I tried using the below code but i could get... (2 Replies)
Discussion started by: girish.raos
2 Replies

9. UNIX for Dummies Questions & Answers

Ignore a string pattern while doing file comparison/difference

Here is my problem. I have to find the differences in 2 XML files This is my Old File contents - File1 <FILEHDR> <Bag xsi:nil='true'></Bag> </FILEHDR> This is my New File contents - File2 <FILEHDR> <Bag xsi:nil='true' ></Bag> </FILEHDR> When I do the following diff -b File1 File2... (1 Reply)
Discussion started by: sksahu
1 Replies

10. Shell Programming and Scripting

How to ignore the Spaces while string Comparison

I want to ignore the spaces while doing string comparison between two files. Iam using "comm" command to compare the files. (1 Reply)
Discussion started by: sudhakaryadav
1 Replies
Login or Register to Ask a Question