LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 08-27-2012, 01:51 PM   #1
Neal000
LQ Newbie
 
Registered: Aug 2012
Posts: 2

Rep: Reputation: Disabled
Compare file extension from two different txt file and find the differences.


I am new to create scripts.

Please help me to prepare one script.
The scenario is : I have two files.
file1 and file2.

file1
doc1.doc
doc2.doc
doc3.txt

file2
doc1.doc
doc2.rtf
doc3.exe

I have to compare each row of both the file, and get the result if the extension is not matching.

o/p shud be.
doc1.doc - ext. match
doc2.doc - ext. not match
doc3.txt - ext. not match.
 
Old 08-27-2012, 02:12 PM   #2
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,032

Rep: Reputation: 275Reputation: 275Reputation: 275
Try this...
Code:
paste $InFile1 $InFile2 \
|awk '{if ($1==$2) print $1, "ext. match";
       else print $1, "ext. not match"}'
Daniel B. Martin
 
Old 08-27-2012, 02:12 PM   #3
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,412
Blog Entries: 1

Rep: Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951Reputation: 951
Hi and welcome to LQ.

What have you done so far? Can you show us your script and where you are stuck?
 
Old 08-27-2012, 02:14 PM   #4
Didier Spaier
Senior Member
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slackware-14.0 on a Lenovo T61 6457-4XG
Posts: 3,644

Rep: Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828Reputation: 828
Hi Neal000

Please exhibit something showing that indeed, you tried to do your homework yourself.

Doing it for you won't make you learn anything.
 
Old 08-27-2012, 02:21 PM   #5
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,032

Rep: Reputation: 275Reputation: 275Reputation: 275
Quote:
Originally Posted by Didier Spaier View Post
Hi Neal000

Please exhibit something showing that indeed, you tried to do your homework yourself.

Doing it for you won't make you learn anything.
You are right. I gave a solution without recognizing the question as homework. Shame on me!

Daniel B. Martin
 
Old 08-28-2012, 01:11 PM   #6
Neal000
LQ Newbie
 
Registered: Aug 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by danielbmartin View Post
You are right. I gave a solution without recognizing the question as homework. Shame on me!

Daniel B. Martin

Thanks Daniel, Actually this is my first script. and I only know some basic commands of linux. I was thinking that this code need some looping concept, I had stuck at beginning only, how to define two different file in loop.
 
Old 08-28-2012, 02:03 PM   #7
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,032

Rep: Reputation: 275Reputation: 275Reputation: 275
Quote:
Originally Posted by Neal000 View Post
Actually this is my first script. and I only know some basic commands of linux. I was thinking that this code need some looping concept ...
No loop required. The paste combines two files to look like this ...
Code:
doc1.doc doc1.doc
doc2.doc doc2.rtf
doc3.txt doc3.exe
... and the awk compares the first word (that's $1) with the second word (that's $2) in each line and outputs the desired text.

Daniel B. Martin
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script to compare numbers in a txt file leopard86 Programming 6 09-11-2012 12:10 AM
[SOLVED] how to install VMware, i have 344MB file with .txt extension skite Linux - Software 3 12-29-2011 04:51 AM
find string in txt file Glenn_UOI Programming 6 10-07-2011 09:50 AM
How can read from file.txt C++ where can save this file(file.txt) to start reading sam_22 Programming 1 01-11-2007 05:11 PM
Txt extension file translation UltraSoul Solaris / OpenSolaris 3 05-21-2005 11:11 AM


All times are GMT -5. The time now is 12:51 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration