0

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

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Salem
0

> 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
0

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?

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.