![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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! |
|
||||
|
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 |
|
||||
|
Quote:
./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 |
|
||||
|
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!! |
|
||||
|
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 |
|
||||
|
Quote:
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|