Re: printing in awk (114 Views)
Reply
Advisor
Jamie Collins
Posts: 28
Registered: ‎10-12-2004
Message 1 of 13 (114 Views)

printing in awk

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

awk '/Start/?????/ {print $0}'
Please use plain text.
Honored Contributor
Sanjay_6
Posts: 5,942
Registered: ‎04-15-2001
Message 2 of 13 (114 Views)

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
Please use plain text.
Advisor
Jamie Collins
Posts: 28
Registered: ‎10-12-2004
Message 3 of 13 (114 Views)

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.
Please use plain text.
Honored Contributor
Sanjay_6
Posts: 5,942
Registered: ‎04-15-2001
Message 4 of 13 (114 Views)

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
Please use plain text.
Advisor
Jamie Collins
Posts: 28
Registered: ‎10-12-2004
Message 5 of 13 (114 Views)

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...
Please use plain text.
Honored Contributor
Sanjay_6
Posts: 5,942
Registered: ‎04-15-2001
Message 6 of 13 (114 Views)

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

Please use plain text.
Advisor
Jamie Collins
Posts: 28
Registered: ‎10-12-2004
Message 7 of 13 (114 Views)

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
Please use plain text.
Honored Contributor
John Poff
Posts: 2,448
Registered: ‎05-22-2001
Message 8 of 13 (114 Views)

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
Please use plain text.
Advisor
Jamie Collins
Posts: 28
Registered: ‎10-12-2004
Message 9 of 13 (114 Views)

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.
Please use plain text.
Honored Contributor
Sanjay_6
Posts: 5,942
Registered: ‎04-15-2001
Message 10 of 13 (114 Views)

Re: printing in awk

Hi,

Try this,

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

Hope this helps.

regds


Please use plain text.
Honored Contributor
Sanjay_6
Posts: 5,942
Registered: ‎04-15-2001
Message 11 of 13 (114 Views)

Re: printing in awk

hi,

Try

echo `cat file_name |awk '{y=x "\n" $0; x=$0};END{print y}'|awk '{for (i=1; i<=NF; i++) s=-$1-s}; END{print s}'`

This will subract the last line from the last-1 line. They have to be numeric values.

someone might have a shorter way.

Hope this helps.

Regds
Please use plain text.
Honored Contributor
Rodney Hills
Posts: 1,679
Registered: ‎09-09-1996
Message 12 of 13 (114 Views)

Re: printing in awk

Here is something pretty straight forward-

awk '/Start/{a=1};{if (a) print $0}' file

(how about assigning points to all that have helped...)

HTH

-- Rod Hills
There be dragons...
Please use plain text.
Honored Contributor
Hein van den Heuvel
Posts: 6,581
Registered: ‎05-19-2003
Message 13 of 13 (114 Views)

Re: printing in awk

awk '{y=x; x=$1} END {print x-y}' inputfile
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation