|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | 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. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
i have two lists,
list1 => abc jones oracle smith ssm tty list2 => abc jones lmn smith ssm xyz now i want to print only those names which are present in list2 and want to remove names from list2 which presents in list1. so i want OUTPUT => lmn xyz because "abc jones smith ssm" from list2 are present in list1. I want to do it in shell script using loop... plz help. |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
i want solution in shell script using loop.
|
|
#4
|
|||
|
|||
|
Why do you need a loop for this? You can loop over the output of the comm command: Code:
comm -13 list1 list2 | while read l ; do echo $l ; done Or use something like this: Code:
while read list2 ; do
grep $list2 list1 &>/dev/null
if [ $? -eq 1 ] ; then
echo $list2
fi
done < list2Last edited by Subbeh; 12-28-2012 at 09:41 AM.. |
| The Following User Says Thank You to Subbeh For This Useful Post: | ||
Killer420 (12-28-2012) | ||
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
Assuming 2 files list1 and list2 has list in same line: Code:
# cat list1 abc jones oracle smith ssm tty # cat list2 abc jones lmn smith ssm xyz Here is a solution in BASH using only built-ins: Code:
#!/bin/bash
FLAG=0
while read list2_line
do
for list2_word in $list2_line
do
while read list1_line
do
for list1_word in $list1_line
do
[[ "$list2_word" == "$list1_word" ]] && FLAG=1
done
[[ $FLAG -eq 0 ]] && echo -e "$list2_word \c"; FLAG=0
done < list1
done
done < list2
echoHere is the output: Code:
# ./search.sh lmn xyz |
| The Following User Says Thank You to Yoda For This Useful Post: | ||
Killer420 (12-28-2012) | ||
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
spcl thnx to bipinajith....
exact ans. which i want.. |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Find the difference between two server lists | proactiveaditya | Shell Programming and Scripting | 3 | 11-01-2012 09:47 AM |
| Shell Script to Create non-duplicate lists from two lists | mlv_99 | Shell Programming and Scripting | 7 | 04-06-2010 08:59 PM |
| `for' unmatched | rechever | Shell Programming and Scripting | 2 | 06-16-2009 03:01 PM |
| done' unexpected and do' unmatched | LRoberts | Shell Programming and Scripting | 6 | 02-02-2009 10:49 AM |
| else unmatched | b.hamilton | Shell Programming and Scripting | 7 | 10-10-2007 05:03 AM |
|
|