Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
Hi
Can someone tell me how to use grep to find a line number of the key words that I'm looking for, say, "connections" in a file and pipe the result into tail to get portion of a file that I needed.
I'm often deaf to 'homework questions', but *this* either sounds like one or a question that assumes methods. What 'portion' do you need and how do the 'connections' lines delimit those portions? Why do you need grep and tail? Etc.
This might be a stupid question, but not a "homework". I'm trying to modify a script to do file editing. I have two huge xml files. Message.xml is auto generated on the daily basis. Reply.xml is manually created once a week. I need to modify the script to search the key word "connections" in Message.xml and insert Reply.xml after the key word. Thought I could use grep to find "connections" line number then use tail to break Message.xml into two temp files - file1, file2. cat Reply.xml to file1, then cat file2 to file1. It may not be a good way of doing it, also I don't know the syntax of piping grep and tail. I'd like to know what is the better way.
This might be a stupid question, but not a "homework". I'm trying to modify a script to do file editing. I have two huge xml files. Message.xml is auto generated on the daily basis. Reply.xml is manually created once a week. I need to modify the script to search the key word "connections" in Message.xml and insert Reply.xml after the key word. Thought I could use grep to find "connections" line number then use tail to break Message.xml into two temp files - file1, file2. cat Reply.xml to file1, then cat file2 to file1. It may not be a good way of doing it, also I don't know the syntax of piping grep and tail. I'd like to know what is the better way.
This might be a stupid question, but not a "homework".
I didn't mean to imply that it was a stupid question at all - sorry for any misunderstanding. I simply meant that the specification of those two tools seemed like it might be a contrived problem rather than a 'real world' problem. As you see, neither of the solutions offered use grep and tail but sed and (what I was originally thinking of) awk. However, given that the input is xml, aren't there xslt approaches that would be specifically designed for this sort of thing?
I'm still not precisely following the situation, based on the absence of example input and output. Hopefully one or both of the suggestions help you out.
Thanks a lot for reply. I tried to use awk as suggested, somehow it didn't work. Maybe it needs some tweek. I'll give sed a shot tomorrow. I know it won't be a big deal if I can write it in c,or xslt. Since I'm modifying a existing bash script. I don't have much choice, which I should have explained earlie. Sorry about that.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.