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.
In part 2 what do you mean "compares"? That suggests that some operation should be performed if some condition is true, but you do not say what.
In general, you can use a while read loop to take input from the keyboard:
Code:
echo -n "Enter a file name> "
while read filename; do
if [ "$filename" = "" ]; then
echo "Nothing entered. I will not ask again"
break
fi
echo "I got this: $filename"
echo -n "Enter another file name> "
done
Shell scripts are really a quick and quite slow glue for combining the functionality of other programs. As I told you in post #5 of this thread, they are not good for line-by-line editing of large sets of data. You should consider writing your program in a language more suited to the task, such as Perl or Python.
For sure awk will be a lot faster than a shell script in this case. Perl will probably be even faster, although it's more to learn than awk, so maybe awk would be easier to get started with.
For example, I created a large test file (15 meg / 100000 lines) and ran the shell script on it. The time used by the process was over 31 seconds. When I did the same thing with an awk program it took just 1.7 seconds. A similar program written in Perl took less than half a second.
The text processing part of the program in awk looks like this:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.