in my file which is a rather long log file it contains many text and tables and there is one table with 15 columns and I am interested to read in the value in column6 and its corresponding value in column2. Trouble is I do not know how to script it as the line number various between different log file and column 1 is different in all the lines within that table so there is nothing to match. Can anyone tell me how I could write this script?
I don't think you are gonna get some assistance unless you post a representative sample content of your file and desired output.
ok if in my log file
there is a table somewhere in that file (amongst plenty other text and tables) that begins like
Table title
==========
line of text
line of text
line of text
$$
column1 column2 column3 column4 column5 column6 etc etc etc
1
2
3
4
.
.
.
.
etc
I want to write a script that if the value on column 6 is greater than say, 2, then return the corresponding value on column 2 on the same line.
I hope that makes it clear.
Basically
awk '$6>2{print $2}' yourfile
May need some tweak depending on the formatting of yourfile
that wont work as I mentioned earlier the file contained plenty other text and other tables so that command will return plenty of junks as well.
Is there a way to specify only "awk"-ing that specific table?
You can do almost anything with awk
. But unless you post your data here, it will be only guessing from us. So post real data, and what you like the output to be.
The only other information I can extract from your vague (if not worse) specification is the table has 15 columns. If that is enough to tell junk from valuable input, extend ctsgnb's proposal:
awk 'NF == 15 && $6>2 {print $2}' yourfile
If that does not solve your problem, be far more specific!
The log file is very long and contains sensitive information that I do not feel comfortable posting online without some heavy editing. I apologise for not being able to be more specific about this.
Ok let say I want to "awk" that specific table within the log file, maybe start awking from 5 lines further down from the table title line where the column data starts until it reaches the line "$$".
Alternatively I could think of maybe I grab those lines first matching between the table title line and the line $$ and then pipes those to awk....
If the data in column 6 is greater than 2 then output the corresponding number in column 2 and store that in a variable.
I hope that is clear enough, and I apologise again for not able to be far more specific about this.
I apologize for not being able to produce a solution better than above proposal given imprecise input data as provided.