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!
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
If you're getting errors, show us the exact code you ran that produced it. We can't tell you what you're doing wrong if we can't see what you did.
And please use ***[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do not use quote tags, bolding, colors, "start/end" lines, or other creative techniques.
In any case, however, don't use expr. Forget that it even exists. It's completely superfluous in all modern shells, which have features built-in that can do everything that old fossil can do and more.
But how are you running the script? What do the values $0, $1, and $2 hold?
I don't think you realize that $0 stores the name of the script, according to how it was launched. It's very rare that you should actually need to use that parameter. $1 holds the first argument to the script.
2) The syntax of head and tail use "-n" to specify their line numbers.
3) QUOTE ALL OF YOUR VARIABLE EXPANSIONS. You should never leave the quotes off a parameter expansion unless you explicitly want the resulting string to be word-split by the shell and any possible globbing patterns expanded. This is a vitally important concept in scripting, so train yourself to do it correctly now. You can learn about the exceptions when you need them.
Yeah? Well, as explained, $1 will be the filename, $2 the "head" number, and $3 the "tail" number. Now it's up to you to figure out how to use them properly.
By the way, I didn't actually test the code above before I posted it. I don't think it gives you exactly what you want. You'll have to modify the math and code flow to get it to output the proper lines. Or use different a different tool, as has also been shown to you.
In any case we've given you all the resources you need to do what you want, so get on it! Post back what you come up with.
Last edited by David the H.; 04-14-2013 at 01:16 PM.