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.
i got the "sn.0???.tx" output, but i can't get that last "t" out of it? what am I doing wrong, I can just add it to the end of every line, that's not a problem, but I'm wondering what's going on here and how to deal with it in case i have something a little less constant in the future.
Thank you, I was about to pull my hair out. I am still curious as to why that is needed. Is there something special about the end of the line or could it be a bug?
ok, i'll keep that in mind. I'm writing some scripts that are going to be dealing with more complex filenames and such. I was just curious if there was something that grep was seeing that I don't know about and may become an issue later with other programs like sed and others that use regular expressions
Mmmmm - don't know about that; lots of blanks in there to trip over the default IFS.
It were me doing this, at about this point I'd be starting to think perl ....
You can set IFS to newline only easy enough.
Perl would be faster though if the file to process is that big, just seemed a bit excessive if he just wants the last field of each rec.
Also depends if this is just a one-off requirement or if its going to be run multiple times.
If you want to use a range of lines, in sed you can start a sed command with a range like,
2000,2500 or use a regular expression like /\[General\]/,/$^/.
You can also use brackets to try to find a match within a range.
Also, using sed, you can add a quit command if you have found a match. That is commonly done to avoid reading all of the lines in a large file.
Code:
2000,2500{
/pattern/<command>
}
2501q
Using grep, look for the option to return a single result. That will abort after finding a match, and won't continue reading till the end of the file looking for another match.
The cut command would be ideal for cutting out a certain field. That is exactly what the command was written for. You could use head to select the top N lines and pipe the output to cut.
If you want to use a certain range of lines, you can use sed to filter through only those lines and pipe the output to the cut command:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.