1

I need to extract the data under "Cell Name" Column knowing that there are different formats before and after the table that I want to extract data from.

%%/*4627363 MML Session=1497784916*/lst gtrx:;%%
RETCODE = 0  Execution succeeded.

List TRX
--------

 TRX ID  TRX Name           Cell Index        Cell Name  Frequency  Is Main 
 0       Model-3900L-60            1        Model-3900L-6520        Yes
 1       Model-3900L-10            0           Model-3900L-1975     Yes
 2       GCAI6008_60081_I_H_DS-10  2       GCAI6008_60081_I_H_DS-1  Yes               

4627363 MML Session=1497784916*/lst gtrx:;%%
    RETCODE = 0  Execution succeeded
3
  • How can you detect the table beginning and end? Commented Jun 18, 2017 at 15:11
  • 1
    add your expected output and what you've tried to solve this... Commented Jun 18, 2017 at 15:21
  • What have you tried? Most of us here are happy to help you improve your craft, but are less happy acting as short order unpaid programming staff. Show us your work so far in an MCVE, the result you were expecting and the results you got, and we'll help you figure it out. Commented Jun 18, 2017 at 16:58

3 Answers 3

1

You can set a flag to 1 when the line with "Cell Name" is found and to 0 when a blank line is found. When the flag is equal to 1, print the 4th field:

awk '!$0{c=0}c{print $4}/Cell Name/{c=1}' file

(note that !$0 returns 1 with an empty line but may also return 1 with for example a line that contains only 0 but it isn't the case with target lines of your file. You can change it to $0=="" that is more explicit if you want.)

Sign up to request clarification or add additional context in comments.

1 Comment

Your final parenthesized statement isn't correct. !$0 will evaluate to false if an input line contains a numeric 0, which of course would not be the same as $0=="". As you say, it doesn't matter for this particular set of input data, but it's a false assertion nonetheless. Perhaps you could improve the wording to clarify this.
1
sed -n '/Cell Name/,/MML/p' file | awk '{print $4}' | head -n -2 | tail -n +2

How it works:
sed -n '/Cell Name/,/MML/p': extract the table based on beginning and end.
awk '{print $4}': select the 4 column, that is "Cell Name".
head -n -2: strip the last 2 invalid end line.
tail -n +2: strip the first invalid beginning line.

1 Comment

While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value.
0
awk '($1 ~ /^[0-9]+/ && ! /%%/){print $4}' file

1 Comment

While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.