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
Compare File Names in Different Directories... stky13 Shell Programming and Scripting 4 05-09-2008 04:36 PM
how to delete file names with $ in them orahi001 UNIX for Dummies Questions & Answers 2 04-11-2008 01:06 PM
Command to list directory names only stevefox UNIX for Dummies Questions & Answers 6 11-29-2007 08:06 PM
Compare file names charbel Shell Programming and Scripting 4 01-31-2007 01:47 PM
How to Pass a list of file names to ls GMMike UNIX for Dummies Questions & Answers 2 11-18-2004 10:33 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-21-2007
eltinator eltinator is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 63
Compare 2 list and delete certain names

Hi,

I currently have a script that takes a list of names and compares it with another list and appends non-duplicate names. I want to modify my script such that it will look at a list of names and for every name preceded by the tag "<delete>" (without the quotes) it checks the other list for that name and will remove it and with whatever else, it will perform the regular functionality of the script like before. So here's an example:

List1:
Jim
Bob
Ed
Hank

List2:
Greg
<delete>Hank
Dave

Result of List1 after the script run:
Jim
Bob
Ed
Greg
Dave

Can anyone help here? Thanks!
  #2 (permalink)  
Old 08-22-2007
aajan aajan is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 80
HI
I Hope this script works




#!/usr/bin/ksh



while read line
do
while read value
do
grep "<delete>" |pattern=`cut -d">" -f2`
if [ $pattern == $line ]
then
sed /$pattern/d file1
sed /$pattern/d file2 |sed '/^ *$/d'
fi
done <file2
done <file1
  #3 (permalink)  
Old 08-22-2007
ahmedwaseem2000 ahmedwaseem2000 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Bangalore
Posts: 219
Try this

Code:
sed -n '/^\<delete\>/d' filename
  #4 (permalink)  
Old 08-22-2007
eltinator eltinator is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 63
Quote:
Originally Posted by aajan View Post
HI
I Hope this script works




#!/usr/bin/ksh



while read line
do
while read value
do
grep "<delete>" |pattern=`cut -d">" -f2`
if [ $pattern == $line ]
then
sed /$pattern/d file1
sed /$pattern/d file2 |sed '/^ *$/d'
fi
done <file2
done <file1
Thanks! I'm assuming file1 and file2 are equivalent to my List1 and List2 right? So I tried running this and it gave me:

./other.sh[10]: [: argument expected
./other.sh[10]: [: argument expected
./other.sh[10]: [: argument expected
./other.sh[10]: [: argument expected
./other.sh[10]: [: argument expected
./other.sh[10]: [: argument expected
Jim
Bob
Ed
Greg
Dave
./other.sh[10]: [: argument expected
./other.sh[10]: [: argument expected


It seemed to have compiled the list right but I'm not sure of the errors. I ran the script pretty much like "./script.sh" Not sure if I was supposed to pass anything into it. Could the new list be stored in some file?

Last edited by eltinator; 08-22-2007 at 12:49 PM.. Reason: update
  #5 (permalink)  
Old 08-22-2007
prez prez is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 7
Hi
the script is fine.

just change the if loop used to
if [ "$pattern" = "$line" ]

Also the script is hard coded.
If you dont have any delete tag in file2, it wud display nothing.
on other hand if you have 2 delete tags it will display the results twice...
if its ok for u ... fine...
or else we ll go for a better solution...

Happy scripting!!
  #6 (permalink)  
Old 08-22-2007
ahmedwaseem2000 ahmedwaseem2000 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Bangalore
Posts: 219
Try this:

Code:
for var in $(cat list2); do

echo $var | grep "^<delete>" > /dev/null
if [[ $? -eq 0 ]]; then
Name=$(echo "$var" | cut -d">" -f2 )
echo $Name
grep -i "$Name" list1 >/dev/null
if [[ $? -eq 1 ]]; then
echo $var
fi

fi
done
  #7 (permalink)  
Old 08-22-2007
prez prez is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 7
Quote:
Originally Posted by ahmedwaseem2000 View Post
Try this:

Code:
for var in $(cat list2); do

echo $var | grep "^<delete>" > /dev/null
if [[ $? -eq 0 ]]; then
Name=$(echo "$var" | cut -d">" -f2 )
echo $Name
grep -i "$Name" list1 >/dev/null
if [[ $? -eq 1 ]]; then
echo $var
fi

fi
done

hi ,
it is fine... but it wud display the results 2 times if there are 2 delete tags in the file2.... which shudnt be the case
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 10:11 AM.


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