Sponsored Content
Top Forums Shell Programming and Scripting how to read the contents of two files line by line and compare the line by line? Post 302620507 by mjavalkar on Sunday 8th of April 2012 02:32:24 PM
Old 04-08-2012
how to read the contents of two files line by line and compare the line by line?

Hi All,

I'm trying to figure out which are the trusted-ips and which are not using a script file.. I have a file named 'ip-list.txt' which contains some ip addresses and another file named 'trusted-ip-list.txt' which also contains some ip addresses. I want to read a line from 'trusted-ip-list.txt' file and check whether the read value exists in 'ip-list.txt' file and write some log info to some other file named 'checked-trust.log' file.

Here is the code i'm trying.. But I'm not able to do so Smilie Smilie..

Code:
trust_file=trusted-ip-list.txt
ip_file=ip-list.txt

while ip= read -r line
do
       test=`grep -w "$line" $ip_file`
       echo " "
       if [ "$ip" -e "$test" ] ; then
           echo "Trusted access at `date` by $line" > checked-trust.log
       else
           echo "Untrusted access at `date` by $line" > check-trust.log
       fi
done < "$trust_file"

Please help me in solving this.. Waiting for a helping hand..

Last edited by Scrutinizer; 04-08-2012 at 03:52 PM.. Reason: code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare two text files line by line

Hi all I need help on comparing two texts files line by line and print the total number of lines matched. Any help is appreciated. Thanks in advance. (4 Replies)
Discussion started by: my_Perl
4 Replies

2. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies

3. UNIX for Dummies Questions & Answers

How to read contents of a file from a given line number upto line number again specified by user

Hello Everyone. I am trying to display contains of a file from a specific line to a specific line(let say, from line number 3 to line number 5). For this I got the shell script as shown below: if ; then if ; then tail +$1 $3 | head -n $2 else ... (5 Replies)
Discussion started by: grc
5 Replies

4. Shell Programming and Scripting

Read each line and saving the line in separate files

Hi Experts, I am having a requirement like this; Input file EIM_ACCT.ifb|1001|1005 EIM_ADDR.ifb|1002|1004 EIM_ABD.ifb|1009|1007 I want to read each line of this file and pass each line,one at a time,as an argument to another script. eg; 1.read first line->store it to a file->call... (2 Replies)
Discussion started by: ashishpanchal85
2 Replies

5. Shell Programming and Scripting

Perl how to compare two pdf files line by line

Hi Experts, Would really appreciate if anyone can guide me how to compare two pdf files line by line and report the difference to another file. (3 Replies)
Discussion started by: prasanth_babu
3 Replies

6. Shell Programming and Scripting

Compare fields in two files line by line

I am new to awk scripting. I want to do a field by word (field) comparison of two files File1.txt and File2.txt. The files contain a list of | (pipe) separated field. **File 1: ------------------- aaa|bbb|ccc|eee|fff lll|mmm|nnn|ooo|ppp rrr|sss|ttt|uuu|vvv** File 2: ... (7 Replies)
Discussion started by: dhruvmohan
7 Replies

7. Shell Programming and Scripting

How to read a two files, line by line in UNIX script and how to assign shell variable to awk ..?

Input are file and file1 file contains store.bal product.bal category.bal admin.bal file1 contains flip.store.bal ::FFFF:BADC:CD28,::FFFF:558E:11C5,6,8,2,1,::FFFF:81C8:CA8B,::FFFF:BADC:CD28,1,0,0,0,::FFFF:81C8:11C5,2,1,0,0,::FFFF:81DC:3111,1,0,1,0 store.bal.... (2 Replies)
Discussion started by: veeruasu
2 Replies

8. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

9. Shell Programming and Scripting

How to read file line by line and compare subset of 1st line with 2nd?

Hi all, I have a log file say Test.log that gets updated continuously and it has data in pipe separated format. A sample log file would look like: <date1>|<data1>|<url1>|<result1> <date2>|<data2>|<url2>|<result2> <date3>|<data3>|<url3>|<result3> <date4>|<data4>|<url4>|<result4> What I... (3 Replies)
Discussion started by: pat_pramod
3 Replies

10. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies
Mono(MozRoots)															    Mono(MozRoots)

NAME
mozroots - Download and import trusted root certificates from Mozilla's LXR into Mono's certificate store SYNOPSIS
mozroots [--import [--machine] [--sync | --ask | --ask-add | --ask-remove]] DESCRIPTION
This program downloads the trusted root certificates from the Mozilla LXR web site into the Mono certificate store. Mono by default does not ship with any default certificates and allows the user to pick its trusted certificates. The mozroots command will bring the Mozilla certificates into your local machine. OPTIONS
--import Import the certificates into the trust store. --sync Synchronize (add/remove) the trust store with the certificates. Synchronize is useful for new Mono installations (no roots) and for automated updates (no user confirmation for addition or removal). --ask Always confirm before adding or removing trusted certificates. Note: The initial import will likely add about 100 new trusted root certificates into your store. You'll have to answer yes to every one of them if this option is specified. --ask-add Always confirm before adding a new trusted certificate. Note: The initial import will likely add about 100 new trusted root cer- tificates into your store. You'll have to answer yes to every one of them if this option is specified. --ask-remove Always confirm before removing an existing trusted certificate. ADVANCED OPTIONS
--url url Specify an alternative URL for downloading the trusted certificates (LXR source format). This should only be useful for testing or if the Mozilla's LXR web site address is changed. It can also be used to cache a local copy of the LXR file into your local intranet. --file name Do not download from LXR but use the specified file. This is useful if many computers have to download the same file from the Inter- net. This way you can keep a local copy on a file server (and minimize network traffic). --pkcs7 name Export the certificates into a PKCS#7 file. This is useful for debugging purpose or for re-importing the same list into other soft- ware. --machine Import the certificate in the machine trust store. The default is to import all trusted root certificates into the current user store. --quiet Limit console output to errors and confirmations messages. This is useful when scripting. EXAMPLES
After the initial Mono installation you'll have no trusted roots certificates pre-installed. Neither will you have some root test certifi- cates installed (your own or the ones provided by using setreg ). In this case the simplest thing to do, if you want to trust all those certificates, is to import and synchronize. $ mozroots --import --sync Mozilla Roots Importer - version 1.1.9.0 Download and import trusted root certificates from Mozilla's LXR. Copyright 2002, 2003 Motus Technologies. Copyright 2004-2005 Novell. BSD licensed. Downloading from 'http://lxr.mozilla.org/seamonkey/source/security/nss/lib/ckfw/builtins/certdata.txt'... Importing certificates into user store... 93 new root certificates were added to your trust store. Import process completed. If you created some test certificates (e.g. for using SSL/TLS with XSP) and/or if your enterprise requires some additional root certifi- cates (e.g. intranet) then you may want to skip the removal part of the process. You can do this by asking for a removal confirmation (--ask-remove option) and answer no when prompted. $ mozroots --import --ask-remove Mozilla Roots Importer - version 1.1.9.0 Download and import trusted root certificates from Mozilla's LXR. Copyright 2002, 2003 Motus Technologies. Copyright 2004-2005 Novell. BSD licensed. Downloading from 'http://lxr.mozilla.org/seamonkey/source/security/nss/lib/ckfw/builtins/certdata.txt'... Importing certificates into user store... 93 new root certificates were added to your trust store. 2 previously trusted certificates were not part of the update. Issuer: CN=Mono Test Root Agency Serial number: 69-B0-E1-4F-88-6E-C7-85-48-0E-74-91-38-76-F4-28 Valid from 9/1/2003 11:55:48 AM to 12/31/2039 1:59:59 PM Thumbprint SHA-1: EF-26-C2-28-11-3F-79-ED-9D-EC-3F-3B-D5-7A-26-F2-7C-9F-FA-63 Thumbprint MD5: AE-19-3E-64-36-21-F2-A4-8B-69-38-CA-64-4B-2E-62 Are you sure you want to remove this certificate ? no You can still use the synchronize option (--sync) if you have activated the default test roots certificate on your system. They will be removed at the end of the synchronization process but you can quickly add them back with the setreg tool. $ setreg 1 true Another option to ease updates is to synchronize your machine trust store (using the --machine option) and keep your customized (test) cer- tificates in your personal store (or vice versa). Note that every user on this computer will be trusting all the newly imported certifi- cates. $ mozroots --import --machine --sync Mozilla Roots Importer - version 1.1.9.0 Download and import trusted root certificates from Mozilla's LXR. Copyright 2002, 2003 Motus Technologies. Copyright 2004-2005 Novell. BSD licensed. Downloading from 'http://lxr.mozilla.org/seamonkey/source/security/nss/lib/ckfw/builtins/certdata.txt'... Importing certificates into user store... 94 new root certificates were added to your trust store. Import process completed. Once the initial import is complete the number of changes (additions or removals) is generally very low. In this case it makes sense to know about any changes (i.e. ask for confirmation). No confirmation will be required if no changes are made to your trust store. $ mozroots --import --ask Mozilla Roots Importer - version 1.1.9.0 Download and import trusted root certificates from Mozilla's LXR. Copyright 2002, 2003 Motus Technologies. Copyright 2004-2005 Novell. BSD licensed. Downloading from 'http://lxr.mozilla.org/seamonkey/source/security/nss/lib/ckfw/builtins/certdata.txt'... Importing certificates into user store... Import process completed. FILES
~/.config/.mono/certs, /usr/share/.mono/certs Contains Mono certificate stores for users / machine. See the certmgr(1) manual page for more information on managing certificate stores. COPYRIGHT
Copyright (C) 2005 Novell. MAILING LISTS
Mailing lists are listed at the http://www.mono-project.com/Mailing_Lists WEB SITE
http://www.mono-project.com SEE ALSO
mono(1),certmgr(1).setreg(1) Mono(MozRoots)
All times are GMT -4. The time now is 12:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy