Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
hi there every one i am a beginner at linux and would really appreciate if someone would be able to help with the following problem. and could yorl explain each step as well since i would like to unerstand whats going on. Thanks> the question is:
Let us assume that in a directory there are some text files whose lines are in no particular order.
Write a script accepting as input any three of these f iles, sorting their lines in alphabetical
order, taking the last lines of these sorted files and creating an output le having these three lines
sorted in reverse alphabetical order.
Tip: use `tail'.The script has to check that only three les are given as input when your script is invoked and
give error messages if more or less than three les are given as input or if any of the input les
does not exist. You have to consider that one, two or three of the input les do not exist and give
one error message
This sounds remarkably like homework... Do you want to tell us what you've written already to have a go at the problem, and where you've got stuck? That will help both you and other people with similar questions more
!/bin/bash
if [ "$#" -ne 3 ]
then
echo "usage: $0 <file1> <file2> <file3>" 1>&2
exit 1
fi
# The file names are "$1", "$2", and "$3".
# What do you want to do with them?
# Here we will read one line from each file, and merge the results to the output
{
while [ 1 ]
do
read -u 3 LINE1
read -u 4 LINE2
read -u 5 LINE3
if [ "$LINE1" != "" -o "$LINE2" != "" -o "$LINE3" != "" ]
then
echo "$LINE1 | $LINE2 | $LINE3"
else
break # Ends while loop
fi
done
} 3<"$1" 4<"$2" 5<"$3"
!/bin/bash
if [ "$#" -ne 3 ]
then
echo "usage: $0 <file1> <file2> <file3>" 1>&2
exit 1
fi
# The file names are "$1", "$2", and "$3".
# What do you want to do with them?
# Here we will read one line from each file, and merge the results to the output
{
while [ 1 ]
do
read -u 3 LINE1
read -u 4 LINE2
read -u 5 LINE3
if [ "$LINE1" != "" -o "$LINE2" != "" -o "$LINE3" != "" ]
then
echo "$LINE1 | $LINE2 | $LINE3"
else
break # Ends while loop
fi
done
} 3<"$1" 4<"$2" 5<"$3"
Ok...where are you stuck?? What error(s) are you getting??
Since nobody has mentioned it, please use descriptive thread titles in future, like you're told to when posting threads. Also, please avoid using "urgent" in thread titles, as your problem isn't urgent for anyone here.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.