how to use grep and tail to get portion of a file
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. Thanks, |
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.
What is your actual input and expected output? |
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.
THX! |
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.
THX! |
Untested .... but you may get the idea.
Code:
awk '{print; if ($0 ~ /connections/){ system(cat reply.xml)}}' message.xml CHeers, Tink |
Here's an example of sed which may work for you.
Code:
sed -n '/connections/,$p' Message.xml > Reply.xml |
Quote:
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.
Again, thanks a lot! |
All times are GMT -5. The time now is 10:26 AM. |