How to compare two files to get correct result.see example?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to compare two files to get correct result.see example?
# 1  
Old 11-03-2011
How to compare two files to get correct result.see example?

Hello,

I have two files A and B .A file consist of the words that user will put whereas file B consist of all user's LDAP a/c.I want here that if user don't mention LDAP a/c in comment than it will exit otherwise success.
File A.I have a solution that I will modify the file A ...just save the file a contents in new line and match each character of file A with with File B.if found than success otherwise false.Please help how could I achieve this.
Code:
This is the user input

File B
Code:
e01234
singh.lal
sumn.kumar

Thanks-
# 2  
Old 11-03-2011
Didn't quite understand your problem. Can you illustrate with some proper example, input and expected output?

--ahamed
# 3  
Old 11-03-2011
see example

user will enter the input in below format
Code:
D1233,S1234 | THIS is user input

Now I want that all the message given by user in the right of the pipe(|) symbol i.e. "THIS is the user input" will save into onr file and after that I will match each word of this with File B where all users's LDAP a/c will save.if any word matches with that then it will success otherwise it will fail and exit.

Hope this clears.

Thanks
# 4  
Old 11-03-2011
You mean to say, you need to compare "THIS is user input" with the file contents having LDAP details? So, in this example, it will be a failure right? Post a input which should be successful.

--ahamed
# 5  
Old 11-03-2011
I don't have any solution..My question is how could I match the each word of user input "THIS is user input" with the file B that stores the name of each user in below format.If THIS word does not match with any name of the file B it will check next word which is "is" in user comment and will compare each word one by one if not matches than exit and print any thing.What would be the code?

File B
Code:
singh.titu
e01234
sumna.kumae

# 6  
Old 11-03-2011
Something like this?
Code:
[root@bt]-> cat run
#!/bin/ksh
echo -e "Enter User Data : \c"
read val

for line in $(echo "${val#*\|}")
do
        grep -q "$line" input_file && echo "Success [$val] [$line]"
done

Scenario:1
Code:
[root@bt]-> ./run
Enter User Data : D1233,S1234 | THIS is user input
[root@bt]->

Scenario:2
Code:
[root@bt]-> ./run
Enter User Data : D1233,S1234 | THIS is user input e01234
Success [D1233,S1234 | THIS is user input e01234] [e01234]

--ahamed
# 7  
Old 11-03-2011
This is not provinding the correct result .Please see below.Its showing the results for only 3 words i.e. is the user while not showing anything for THIS and input word.
One more thing I want to cleae here that my file where all users LDAP a/c saves in below format
Code:
Makan Lal
Shanu Kumar
Pink Singh

Code:
Enter User Data : D1234,S123 | THIS is the user input
Success [D1234,S123 | THIS is the user input] [is]
Success [D1234,S123 | THIS is the user input] [the]
Success [D1234,S123 | THIS is the user input] [user]

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

CUT command not giving correct result inside loop

Hi, i have a source file and have 3 columns and separated by "|" .i want to split this 3 columns in different variable.When i am executing this values indivisually giving correct result but when the same execute inside a for loop,it's giving issues. Src file(jjj.txt) -------... (8 Replies)
Discussion started by: raju2016
8 Replies

2. Shell Programming and Scripting

How to compare 2 files and create a result file with unmatched lines from first file.?

HI, I have 2 text files. file1 and file2. file1.txt (There are no duplicates in this file) 1234 3232 4343 3435 6564 6767 1213 file2.txt 1234,wq,wewe,qwqw 1234,as,dfdf,dfdf 4343,asas,sdds,dsds 6767,asas,fdfd,fdffd I need to search each number in file1.txt in file2.txt's 1st... (6 Replies)
Discussion started by: Little
6 Replies

3. Shell Programming and Scripting

How to compare the current result with previous line result.?

Hi Gurus, I have requirement to compare current result with previous reuslt. The sample case is below. 1 job1 1 1 job2 2 1 job3 3 2 job_a1 1 2 job_a2 2 2 job_a3 3 3 job_b1 1 3 job_b2 2 for above sample file, GID is group ID, for input line, the job run... (1 Reply)
Discussion started by: ken6503
1 Replies

4. Shell Programming and Scripting

Compare 2 file and write result

Hi friends...I have 2 files, file1.txt and reference.txt I could able to find difference using diff and following command awk 'NR == FNR { A=1; next } !A' reference.txt file1.txt above command listing data which is not in reference.txt 12.12 87 11.95 88 11.83 89 12.55 84... (12 Replies)
Discussion started by: Akshay Hegde
12 Replies

5. Shell Programming and Scripting

Compare two files Field by field and output the result in another file

Hi Friends, Need Help. I have file1.txt as File1.txt |123|A|7267|Hyder|Cross|Sell|7801 |995|A|7051|2008|Lunar|New|Year|Promotion|7801 |996|A|7022|Q108|Targ|Prospect|&|SSCC|Savings|Promo|7801 |997|A|7182|Q1|Feb-Apr|08|Credit|ITA|PA|SBA|Campaign|7801 File2.txt... (7 Replies)
Discussion started by: i150371485
7 Replies

6. Shell Programming and Scripting

Compare 2 result sets using a script

select colname from syscat.columns where tabname='t' and tableschema='s' output is columnnames which are in part of primary key PK1 PK2 PK3 PK4 PK5 select colname from syscat.columns where tabname ='t1' and tableschema='s' output is columnnames which are in part of primary key for... (3 Replies)
Discussion started by: kanakaraju
3 Replies

7. Shell Programming and Scripting

compare two files, diff the result

Hi Everyone, 1.txt 00:01:01 asdf 00:33:33 1234 00:33:33 0987 00:33:33 12 00:33:33 444 2.txt vvvv|ee 444|dd33|ee dddd|ee 12|ee 3ciur|fdd the output should be: (6 Replies)
Discussion started by: jimmy_y
6 Replies

8. Shell Programming and Scripting

How to compare result lpstat with hostsfile

Hi there all, I got a long list of printers installed and a longer list of printers in my hosts file. In the hosts file I got a even longer list of printers in the hosts file I got the IP adress of all printers next to the printer name. How can I get a script working to get the printers... (0 Replies)
Discussion started by: draco
0 Replies

9. UNIX for Dummies Questions & Answers

Compare 2 files and output result in pop up window

Need help ! how do i compare 2 files and if there is a difference, output a massage in a pop up window? the script meant to run using crontab. (2 Replies)
Discussion started by: hongsh
2 Replies

10. UNIX for Dummies Questions & Answers

While finding compare the result with given string

Hello, There are directories named by "yyyyMMdd" format. The one directory name is given and I should find & print that directory & its previous days directory names if exist. For example: 20080401 20080402 20080403 20080404 ... The given date: 20080403 The result: 20080403... (4 Replies)
Discussion started by: mr_bold
4 Replies
Login or Register to Ask a Question