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.
Thats a great help thank you vineethsp !
However as I am a newbie Im still stuck with the proper syntax for it!
I know to pass the parameters are $0 $1 $2 ... etc.(http://www.dreamsyssoft.com/unix-she...s-tutorial.php)
Distribution: RedHat Enterprise Linux Server Edition 5.5
Posts: 13
Rep:
Quote:
Originally Posted by woodyhead
Thats a great help thank you vineethsp !
However as I am a newbie Im still stuck with the proper syntax for it!
I know to pass the parameters are $0 $1 $2 ... etc.(http://www.dreamsyssoft.com/unix-she...s-tutorial.php)
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 12:16 PM.
Reason: fixes
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.