Read second line from file with awk and use as variable.
Hello.
I have a file like this: Code:
13:36 PHP Code:
13:36 13:38 13:40 13:45 13:50 13:55 It works fine this way, but how can I make awk read the second line and print results without problem? Since the file I want to read is in the following format: 13:36 13:38 13:40 13:45 Thanks in Advanced, for any help. |
something like this should work
Code:
awk ' NR % 2 == 0 { hora1=substr($1,1,2); minuto1=substr($1,4,2) } |
Hey cool :D it does work :D I really appreciate a lot your help.
I am extremely newbie in awk programming, so there,s a bunch of things I still need to learn and understand. Your modification does work very well :) There,s a little inconvenience, maybe I have missed something here don,t know. Well I have a file (let's call it textfile.txt) with the following times let said: 13:30 13:35 13:50 etc, etc. When I execute your awk script like this: bash$ awk -f myawkscript.awk < textfile.txt The results I get back are as follow: -13:30 0:15:0 0:15:0 How can I omit printing the first line from the textfile.txt? I just want the results from the times calculation. Sorry if this is too newbie :) I really appreciate any help you can provide. |
I think I made a mistake, first you need NR % 2 == 1 and in the second line NR % 2 == 0.
|
Thanks Pan64 :) I made the change, but unfortunately it keeps printing the first line on stdout. What I did was, a bash script that do a tail command that read only the last 2 lines, so this way I avoid any below line. It works this way :)
I appreciate all your help in providing a solution for my request. Thanks :) |
All times are GMT -5. The time now is 01:16 PM. |