LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 09-18-2011, 04:14 PM   #1
laukman
LQ Newbie
 
Registered: Sep 2011
Posts: 3

Rep: Reputation: Disabled
urgently needs a response


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
 
Old 09-18-2011, 04:18 PM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
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
 
Old 09-18-2011, 04:25 PM   #3
laukman
LQ Newbie
 
Registered: Sep 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
hey okay dis is what i have so far

!/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"
 
Old 09-18-2011, 05:21 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,646

Rep: Reputation: 7969Reputation: 7969Reputation: 7969Reputation: 7969Reputation: 7969Reputation: 7969Reputation: 7969Reputation: 7969Reputation: 7969Reputation: 7969Reputation: 7969
Quote:
Originally Posted by laukman View Post
hey okay dis is what i have so far
Code:
!/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??
 
Old 09-18-2011, 06:30 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,360

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
A couple of small tips
Code:
!/bin/bash
should be
Code:
#!/bin/bash
also, try
Code:
set -xv
as the 2nd line; shows you what the parser is doing/seeing.

Useful links
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
1 members found this post helpful.
Old 09-19-2011, 12:33 AM   #6
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache response "HTTP request sent; waiting for response" too long ALInux Linux - Server 1 07-19-2011 06:45 PM
[SOLVED] Need Help Urgently maverick9888 Linux - Newbie 5 05-26-2011 05:08 AM
LXer: A Response to HIMSS "Call to Action" on the American Recovery and Response Act LXer Syndicated Linux News 0 02-13-2009 01:40 AM
Help me! Urgently bokra Linux - Kernel 2 04-30-2006 10:36 PM
Need Help Urgently andrewt Linux - Software 4 08-07-2003 02:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration