1748270 Members
3749 Online
108760 Solutions
New Discussion юеВ

printing in awk

 
Jamie Collins
Advisor

printing in awk

How do I print from a certain spot in a file to the end of the file??

awk '/Start/?????/ {print $0}'
12 REPLIES 12
Sanjay_6
Honored Contributor

Re: printing in awk

Hi Jamie,

Try this awk one liner.

http://www.sap-basis-abap.com/unix/awk-one-liner-tips.htm

If it helps, print and keep a copy for future reference.

Hope this helps.

regds
Jamie Collins
Advisor

Re: printing in awk

The example I was looking for isn't in there. I need to know what the end of file flag is in awk?? I thought it was $^ but that doesn't work.
Sanjay_6
Honored Contributor

Re: printing in awk

Hi,

Give us an example of what the line looks like at present and what you want it look like after awk. Are you trying to get a string after a column position or a match_case position.

Hope this helps.

Regds
Jamie Collins
Advisor

Re: printing in awk

0 Awaiting Message
7856545 458458454 9987787
0.0 0.0 0.0 0.0
0.1 0.2
0.2

79 RSSD Logical thread
2154845 542154 2154325
0.0 0.1 0.0 0.10
0.1 0.0
0.10

80 RSSD_thread RSSD
4578512 2154215 2154687
100.6 110.8 0.1 0.1
1645.88 2489.01
2489.10


The last two lines of the file are always going to be the lines I want so I guess if we could print out just the last two lines that would work also...
Sanjay_6
Honored Contributor

Re: printing in awk

Are we to assume that this is a single file and you want the last two lines. How about tail -2 file_name

here
cat file_name
0 Awaiting Message
7856545 458458454 9987787
0.0 0.0 0.0 0.0
0.1 0.2
0.2

79 RSSD Logical thread
2154845 542154 2154325
0.0 0.1 0.0 0.10
0.1 0.0
0.10

80 RSSD_thread RSSD
4578512 2154215 2154687
100.6 110.8 0.1 0.1
1645.88 2489.01
2489.10

And the results of "tail -2 file_name" would be
1645.88 2489.01
2489.10

Is this what you want.

Hope this helps.

Regds

Jamie Collins
Advisor

Re: printing in awk

I was using tail but I already have an awk program and didn't want to deviate away from it... I'll just use the tail and put it into a temp file... Thanks
John Poff
Honored Contributor

Re: printing in awk

Hi,

Just for reference, you can get awk to print from a specific line to the end of the file. I got it to work like this, there may be a better way:

awk '/Start/,/\*/ {print}' somefile


JP
Jamie Collins
Advisor

Re: printing in awk

Thanks..
I have another question though...

I get output like this...

1654.28
2498.07

How do I subtract those two numbers? They're on seperate lines.
Sanjay_6
Honored Contributor

Re: printing in awk

Hi,

Try this,

awk '{y=x "\n" $0; x=$0};END{print y}' file_name

Hope this helps.

regds