LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   awk print to file question (http://www.linuxquestions.org/questions/programming-9/awk-print-to-file-question-860890/)

takayama 02-05-2011 10:55 AM

awk print to file question
 
Hello
Im spliting a large file into small once based on the $4 in the big file. Then i want to make a script that prints some info from the "smaller file" (lets call it #1) into a other document (lets call it #2 document). The first stuff in the #2 should be a record that comes from the #1. But i only want to print that stuff once. If i do a normal {print $4} log.txt > test.txt it print the $4 once for every new line in log.txt.

crts 02-05-2011 12:54 PM

Hi,

I quite cannot grasp what you are actually trying to achieve. You are being very vague in your description, e.g.
Quote:

The first stuff in the #2 should be a record that comes from the #1.
So what is in #1, what else is in #2?
Quote:

But i only want to print that stuff once. If i do a normal {print $4} log.txt > test.txt it print the $4 once for every new line in log.txt.
???
Since awk is a line editor that is the normal behavior. But you can 'workaround' that.
So from what I have understood so far you do have a script that does what you want but you'd like to improve it, make it more effective. Maybe you should post what you have so far. This will then hopefully clear things up of what your goal is. Some sample data of the ?three? involved files would be helpful, too. What do they look before processing and what are they supposed to look afterwards.

takayama 02-05-2011 03:53 PM

Ok i will try to make it a bit more simple.


I have one log file (in raw syslog format) from a special host, example 192.168.1.1. Im trying to build a script that extract some info from that file to a other file (acctuly a html page).
I want the first line in the html page to be like "Stats for $4". But if i run it with {print "Stats for" $4) it will print Stats for 192.168.1.1 each time for every line, witch i dont want. And i cant really use it in BEGIN becouse BEGIN dont read from the file (ex {print "yo" $4} in BEGIN just print yo.

takayama 02-05-2011 04:21 PM

Find it, simple stuff ;) NR == 1 { print "test" }


All times are GMT -5. The time now is 01:31 PM.