Extract string from multiple file based on line count number
Hi,
I search all forum, but I can not find solutions of my problem
I have multiple files (5000 files), inside there is this data :
FILE 1:
FILE 2:
FILE 3:
I need to extract this data so that result in another single file (call it result.txt) will be :
I am truly newby with awk/perl,
Any helps are very much appriciated.
Gunk.
Last edited by Franklin52; 04-04-2011 at 09:14 AM..
Reason: Please use code tags
The file is just like it is.
Indeed there is no space, just continuously no.
The original data has the same start line no. (when I check in notepad),
For example,
the resulting 1st coulomb should started between linecount no 20 to 33 of the original file 1,
and the 2nd col. also linecount 20 to 33 of file 2,
and so on.. it is the same also for all files.
Ok, your data are mess, the - with different meaning to make the troubles.
use below command to fix it first (if your sed support -i option)
...<snip>...
[/CODE]Of course, if your sed don't support -i option, I will give you solution later.
You can just fix that in the awk script. Fix the record and assign the result to $0. That will force recalculation of NF and reassignment to each field variable.
Regards,
Alister
---------- Post updated at 10:39 AM ---------- Previous update was at 09:54 AM ----------
The simplest way to do that is probably:
If using gawk, then I suppose gensub with backreferences can manage it in one stroke, like the sed suggestion above.
if there's a file containing:
money king money queen money cat money also money king
all those strings are on one line in the file.
how can i find out how many times "money king" shows up in the line?
egrep -c "money king" wont work. (7 Replies)
I have a LOG file which looks like this
Import started at: Mon Jul 23 02:13:01 EDT 2012
Initialization completed in 2.146 seconds.
--------------------------------------------------------------------------------
--
Import summary for Import item: PolicyInformation... (8 Replies)
This is a variation of an earlier post found here:
unixcom/shell-programming-scripting/159821-merge-two-non-consecutive-lines.html
User Bartus11 was kind enough to solve that example.
Previously, I needed help combining two lines that are non-consecutive in a file. Now I need to do the... (7 Replies)
Gurus,
Need little guidance.
I have A.txt and B.txt file. B.txt file contains Unique strings.
Sample content of B.txt file for which i cut the fourth column uniquely and output directed to B.txt file
And A.txt file contains the above string as a fourth column which is last column.
So A.txt... (7 Replies)
Hello everybody!
I am quit new here and hope you can help me.
Using an awk script I am trying to extract data from several files. The structure of the input files is as follows:
TimeStep parameter1 parameter2 parameter3 parameter4
e.g.
1 X Y Z L
1 D H Z I
1 H Y E W
2 D H G F
2 R... (2 Replies)
Hello People,
I have the following contents in an XML file
...........
...........
..........
...........
<Details = "Sample Details">
<Name>Bob</Name>
<Age>34</Age>
<Address>CA</Address>
<ContactNumber>1234</ContactNumber>
</Details>
...........
.............
.............. (4 Replies)
Hello,
I am having trouble extracting a specific line from a file when the line number is known. My first attempt involved grep -n 'hi' (the word 'hi will always be there) to get the line number before the line that I actually want (line 4).
Extra Notes:
-I am working in a bash script.
-The... (7 Replies)
I have a shell script and want to assign a value to a variable. The value is the line exctrated from a file using the line number. The line number it is not fix, and could change any time.
I have tried sed, awk, head .. See my script
# Get randome line number from the file
#selectedline = `awk... (1 Reply)
I need to count the number of files which have a search string, but counting the file only once
if search string is found.
eg: File1: Please note that there are 2 occurances of "aaa"
aaa
bbb
ccc
aaa
File2: Please note that there are 3 occurances of "aaa"
aaa
bbb
ccc... (1 Reply)