The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Operating Systems
> UNIX Help
|
Unix shell script help
Discuss Unix shell script help in the UNIX Help forum on Dev Shed. Unix shell script help UNIX Help forum discussing the Unix Operating System and all variants including Irix, Solarix, and AIX. Unix was designed as a true multi-user operating system.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

June 9th, 2012, 11:32 PM
|
|
Registered User
|
|
Join Date: Mar 2012
Posts: 6
Time spent in forums: 1 h 2 m
Reputation Power: 0
|
|
|
Unix shell script help
I want to compare two files.
File1.txt contains the following data
Hi
How
are
you?
File2.txt contains the following data
hello
world
good morning
Hi
How
are
you?
What i need is.. I want to check whether the content in File1.txt present in File2.txt (In Same sequence) or not.
Condition is data should be in same sequence after "Hi" there should be "How" and then in next line "are" and then "you?"
can please help me..
|

June 10th, 2012, 06:13 AM
|
|
Registered User
|
|
Join Date: May 2012
Posts: 14
Time spent in forums: 6 h 52 m 49 sec
Reputation Power: 0
|
|
|
Can file2 contains other lines after those in file1?
You could use the command diff to compare the files. But if there are other checks to do, better build up a script that compare files line by line.
For example, should the script consider it correct if the content in file1 starts from line 5 in file2, having lines from 0 to 4 with any other words?
|

June 10th, 2012, 06:18 AM
|
|
|
|
grep -n will be your friend.
__________________
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc
|

June 11th, 2012, 08:06 AM
|
|
Registered User
|
|
Join Date: Mar 2012
Posts: 6
Time spent in forums: 1 h 2 m
Reputation Power: 0
|
|
Quote: | Originally Posted by gregorio.palama Can file2 contains other lines after those in file1?
You could use the command diff to compare the files. But if there are other checks to do, better build up a script that compare files line by line.
For example, should the script consider it correct if the content in file1 starts from line 5 in file2, having lines from 0 to 4 with any other words? |
Reply:
File 2 can contain other data after those lines.
The content in File 1 should present in File 2 exactly any where but in sequence.
|

June 11th, 2012, 08:32 AM
|
|
Registered User
|
|
Join Date: Mar 2012
Posts: 6
Time spent in forums: 1 h 2 m
Reputation Power: 0
|
|
Quote: | Originally Posted by SimonJM grep -n will be your friend. |
Sorry it was not working.
i want to search all the lines in file1 with file2. can please help me with any logic.. Need it in emergency
|

June 12th, 2012, 07:23 AM
|
|
|
|
How general purpose would this be? How many times will the lines from file 1 appear in file 2? How many lines would be in file 1?
|

June 12th, 2012, 08:40 AM
|
|
Registered User
|
|
Join Date: Mar 2012
Posts: 6
Time spent in forums: 1 h 2 m
Reputation Power: 0
|
|
Quote: | Originally Posted by SimonJM How general purpose would this be? How many times will the lines from file 1 appear in file 2? How many lines would be in file 1? |
The data in file 1 appears only once in file 2.
File 1 may contain any number of lines but the exact data in File 1 should appear in File 2.
Any help please
|

June 12th, 2012, 12:49 PM
|
|
|
Ok, in which case:
Code:
tmpf=file.tmp
grep -f File1.txt File2.txt > $tmpf
diff -q $tmpf File1.txt
Should give you a start - there are issues with this method, so be warned!
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|