The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need Script to check file exist and compare rbknisely UNIX for Dummies Questions & Answers 1 01-16-2008 01:08 AM
How to compare two flat files and get changed data jtshashidhar Shell Programming and Scripting 3 01-29-2006 10:26 PM
How to compare data in two flat files and update them? rajus19 Shell Programming and Scripting 3 11-08-2005 11:13 AM
Compare Data in the same file lweegp UNIX for Dummies Questions & Answers 1 10-17-2005 02:32 AM
Compare data files ithomp Shell Programming and Scripting 1 06-15-2004 10:08 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-13-2005
lweegp lweegp is offline
Registered User
  
 

Join Date: Oct 2005
Location: singapore
Posts: 107
Question Compare data in 2 files and delete if file exist

Hi there,

I have written a script called "compare" (see below) to make comparison between 2 files namely test_put.log and Output_A0.log

#!/bin/ksh

while read file
do
found="no"
while read line
do
echo $line | grep $file > /dev/null
if [ $? -eq 0 ]
then
echo $file found
found="yes"
break
fi
done < test_put.log
if [ $found = "no" ]
then
echo $file not found
fi
done < Output_A0.log

I have managed to extract the output as follows:

root@mapserv12 #./compare
A0567 found
A0678 found
A0789 found

Can someone give me some clues on how can I delete the files which are found? I really welcome ideas n suggestions. U may even change/ edit my script. Really need some guidance on this. Many Thanks.


Lweegp
  #2 (permalink)  
Old 10-13-2005
guptan guptan is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 19
I am not sure my understanding of your requirement is correct. If you simply wants to delete the files that are found then just use rm command. I still not sure whether it solves your requirement or not.

#!/bin/ksh

while read file
do
found="no"
while read line
do
echo $line | grep $file > /dev/null
if [ $? -eq 0 ]
then
echo $file found
found="yes"
rm $file
break
fi
done < test_put.log
if [ $found = "no" ]
then
echo $file not found
fi
done < Output_A0.log

Cheers
Narayana Gupta
  #3 (permalink)  
Old 10-13-2005
lweegp lweegp is offline
Registered User
  
 

Join Date: Oct 2005
Location: singapore
Posts: 107
hi Nara,

I'll try and let u know. thanks.
  #4 (permalink)  
Old 10-13-2005
lweegp lweegp is offline
Registered User
  
 

Join Date: Oct 2005
Location: singapore
Posts: 107
hi nara,

it works fine now. many thanks.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:08 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0