LinuxQuestions.org
Help answer threads with 0 replies.
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, 05: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, 05:18 PM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
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, 05: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, 06:21 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,336

Rep: Reputation: 3895Reputation: 3895Reputation: 3895Reputation: 3895Reputation: 3895Reputation: 3895Reputation: 3895Reputation: 3895Reputation: 3895Reputation: 3895Reputation: 3895
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, 07:30 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
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, 01: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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 07:45 PM
[SOLVED] Need Help Urgently maverick9888 Linux - Newbie 5 05-26-2011 06: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 02:40 AM
Help me! Urgently bokra Linux - Kernel 2 04-30-2006 11:36 PM
Need Help Urgently andrewt Linux - Software 4 08-07-2003 03:57 PM


All times are GMT -5. The time now is 08:35 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration