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?
# 8  
Old 11-03-2011
I am totally confused with what you want! I don't even understand how the code I gave you is cerating the output you pasted.

Lets do it again. Provide the input file (proper file), the user input and expected output. Provide 2 example, 1 correct and 1 incorrect scenarios.

--ahamed
# 9  
Old 11-04-2011
File A
Code:
Cippu Kaliyil
Madhuri Kajare
Hitesh Sabharwal
Andy Phillipson
Jeffery Baxter
Monica Marshall
Anudeep Bhavannavar
David Hanson
Antoniette Engelker
wmb dev
wmb preprod
wmb prod
Neeta Gawde
Sapan Jain
Ketan Gadre
Service Account SCMWebPortal
Steven Ray
Claudia Rourke
Veronica Gomez
Brenda Heard
Patricia Long
Kenneth Moyer
Jitendra Madduri
Mickey Sumpter
Terrie Boyles
Patrick Garrity
Vicki Boyd
Michael Zingarelli

File A consist of all user name in the above format.Now I want a code or script while user enter the data e.g
this way
Code:
D1234,S1234 | I am Indian

Now if you check the left part of user input it consist of three words (I am Indian) which doesn't exist in File A so script should exit or if the name exist in user input then script should return success.

Code:
D1234,S1234 | I am Patricia Long

I above user input you can see that it consist of user name Patricia Long
which exist in File A so it is valid.

Thanks
# 10  
Old 11-04-2011
Try this...
Code:
#!/bin/ksh
echo -e "Enter User Data : \c"
read val
val=$(echo "${val#*\|}" | sed 's/ /|/g;s/^|//g')
egrep -w "($val)" input_file && echo "Success"

Code:
root@bt:/tmp# ./run
Enter User Data : D1234,S1234 | I am Patricia Long
Patricia Long
Success

Code:
root@bt:/tmp# ./run
Enter User Data : D1234,S1234 | I am Indian

--ahamed
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