Dear Experts,
I have a file looks like:
Code:
input_wez
.....
.....
.....
end
useless content
input_rty
....
....
....
end
uesless content
input_utl
....
....
....
end
uesless content
...
...
I want to split the file based on the patter of each input_***/end coupling. Eliminate the useless content.
The output file should have a name labled by the three code after "input_" and a sequence number, like:
Code:
wez_1.txt
rty_2.txt
utl_3.txt
...
***_9999.txt
...
The content of each file should be:
Please notice that there is not line of "input_***" and no empty line saved in the output file! The file started right from the content which was 2 lines after the "input_***" title in the big file.
No "input_***" and No that empty line between the "input_***" and the content.
I modified some other's code and now can achieve close result by:
Code:
awk -F_ '/input/{ f=$2; n++; next} f{print > f "_" n ".pdb"} /END/{close(f);f=x}' INPUTFILE
But the output file from this code looks like:
Code:
#EMPTY LINE APPEARED HERE
....
....
....
end
Please notice that the empty line which is in between of the "input_***" and the content can not be eliminated by this code.
My questions are:
1. How to eliminate the empty line by the simplest modification in above awk code
2. In the above awk code, what is the meaning of the f before
Code:
f{print > f "_" n ".pdb"}
Why when I replace it by
Code:
{print > f "_" n ".pdb"}
it gave me file name as _n.pdb, but not ***_n.pdb anymore?
Is this a general method when I am trying to write to files?
What is the general usage and functional purpose of
?
3. In the end of my awk code, when I close the file by
Why do I need to reset f to x? If I do not do this, why I get the "useless content" at the end of each output file? What is the logic behind?
Could you please, may be, if you understand better the code than me, explain a bit more for these two parts of the code?
I know, may be these questions are annoying. But now I am really tring very hard to understand AWK and I really hope I can use it more freely. To do that I have to have a better and deeper understanding. I hope these question may not disturb you too much. But, if you don't like it, please just ignore it. I would thank you all the same!!!