|
Home > Archive > Unix Programming > September 2006 > UNIX Shell Program
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
UNIX Shell Program
|
|
|
| How to compare two files??
One file is an input file created by me and it will be as follows :
MANOJ TALAGADADEEVI
AJAY GUPTA
CHAITANYA KIRAN DALIPARTHY
....like these.
This means the input file consists of First and Last names of some
persons.
Another file is a "passwd file" present in the UNIX system.
My aim is to compare these two files for a match in first name or last
name or both .
And if a match founds ..then i have to place those names in some other
new files.
I am thinking to write thisprogram in C shell .Is this shell Ok ?
I think i have to use ..:: ypcat passwd , awk and egrep
Anybody help me out plz
Its very urgent.
| |
| Pascal Bourguignon 2006-09-25, 7:35 pm |
| "mano" <manoj854@gmail.com> writes:
> How to compare two files??
>
> One file is an input file created by me and it will be as follows :
> MANOJ TALAGADADEEVI
> AJAY GUPTA
> CHAITANYA KIRAN DALIPARTHY
>
> ...like these.
>
> This means the input file consists of First and Last names of some
> persons.
>
> Another file is a "passwd file" present in the UNIX system.
>
> My aim is to compare these two files for a match in first name or last
> name or both .
> And if a match founds ..then i have to place those names in some other
> new files.
>
> I am thinking to write thisprogram in C shell .Is this shell Ok ?
>
> I think i have to use ..:: ypcat passwd , awk and egrep
> Anybody help me out plz
Basically, you can compare files with cmp or diff.
cmp compares byte by byte, while diff compares line by line.
Let's choose diff for what you want.
Now the question is to have similar lines in both files, and sorted in
about the same order.
awk -F'[:,]' '{print $5}' /etc/passwd | sort -fu > users-in-passwd
sort -fu input > users-in-input
diff -itwb users-in-input users-in-passwd
You might want to try:
diff -yitwb --width=80 users-in-input users-in-passwd
too.
> Its very urgent.
Thanks to remember me I've urgent things to do too.
I think I'll do them before sending this answer...
--
__Pascal Bourguignon__ http://www.informatimago.com/
ATTENTION: Despite any other listing of product contents found
herein, the consumer is advised that, in actuality, this product
consists of 99.9999999999% empty space.
| |
| Michal Nazarewicz 2006-09-27, 7:37 pm |
| "mano" <manoj854@gmail.com> writes:
> How to compare two files??
>
> One file is an input file created by me and it will be as follows :
> MANOJ TALAGADADEEVI
> AJAY GUPTA
> CHAITANYA KIRAN DALIPARTHY
>
> ...like these.
>
> This means the input file consists of First and Last names of some
> persons.
>
> Another file is a "passwd file" present in the UNIX system.
>
> My aim is to compare these two files for a match in first name or last
> name or both .
> And if a match founds ..then i have to place those names in some other
> new files.
>
> I am thinking to write thisprogram in C shell .Is this shell Ok ?
>
> I think i have to use ..:: ypcat passwd , awk and egrep
> Anybody help me out plz
> Its very urgent.
I admit I don't understand what are you talking about but maybe:
#v+
xargs echo <file-with-names >temporary-file
fgrep -i -f temporary-file <passwd-file >output-file
rm -f --temporary-file
#v-
or maybe:
#v+
#! /bin/sh
while read F L; do
if fgrep -i -e "$F" -e "$L" <passwd-file >/dev/null 2>&1; then
echo "$F $L"
fi
done <file-with-names >output-file
#v-
--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>--<jid:mina86*jabber.org>--ooO--(_)--Ooo--
| |
| Chris F.A. Johnson 2006-09-28, 7:27 pm |
| On 2006-09-25, mano wrote:
> How to compare two files??
>
> One file is an input file created by me and it will be as follows :
> MANOJ TALAGADADEEVI
> AJAY GUPTA
> CHAITANYA KIRAN DALIPARTHY
>
> ...like these.
>
> This means the input file consists of First and Last names of some
> persons.
>
> Another file is a "passwd file" present in the UNIX system.
>
> My aim is to compare these two files for a match in first name or last
> name or both .
> And if a match founds ..then i have to place those names in some other
> new files.
>
> I am thinking to write thisprogram in C shell .Is this shell Ok ?
The C shell is not recommended for scripting. See:
<http://www.grymoire.com/Unix/CshTop10.txt>
<http://www.grymoire.com/Unix/Csh.html#uh-0>
<http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/>
> I think i have to use ..:: ypcat passwd , awk and egrep
> Anybody help me out plz
> Its very urgent.
--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
|
|
|
|
|