Hi, I've got 2 problems with sh:

1) I have a list of logins, seperated by a space (in a logins.txt file, like so: login1 login2 login3). I'd like to display those login names which are online AND on that list. So I made a list of those online:
users > online.txt
and now how to compare the two files and display those logins which are on both lists? I tried with diff and cmp, but failed :/
Perhaps there is an easier way to do that, now making the 2nd file?

2) I'd like to have a script that as an argument takes a file name and shows it's conent with "more" if thats a normal file, "ls" if thats a directory or a message like "that neither file nor dir" it it is neither of them. How to do that?

All help appreciated

Recommended Answers

All 3 Replies

> 1) I have a list of logins, seperated by a space (in a logins.txt file, like so: login1 login2 login3).
All on one line?
Or like
login1 login2 login3
login5 login5

You could try this

for i in `cat logins.txt`; do grep $i online.txt; done

For the other one, it would be something like

if [ -f $f ]; then
elif [ -d $f ]; then
else
fi

Ah, lame me, didn't know about those -d = dir, -f = file :/
Thanks, that one works fine, but the 1st one just prints the content of the online.txt file, twice, in two lines. How come?

Experiment with for i in `cat logins.txt`; do echo $i ; done until you get your login list printed, one per line.
You may have to experiment with the command between the back-ticks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.