LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-05-2011, 10:55 AM   #1
takayama
Member
 
Registered: Sep 2009
Posts: 93

Rep: Reputation: 0
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.
 
Old 02-05-2011, 12:54 PM   #2
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,604

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
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.
 
Old 02-05-2011, 03:53 PM   #3
takayama
Member
 
Registered: Sep 2009
Posts: 93

Original Poster
Rep: Reputation: 0
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.
 
Old 02-05-2011, 04:21 PM   #4
takayama
Member
 
Registered: Sep 2009
Posts: 93

Original Poster
Rep: Reputation: 0
Find it, simple stuff NR == 1 { print "test" }
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
awk: how can I print out a message to the screen when redirecting the output to file. quanba Programming 5 03-28-2010 05:25 PM
Text file manipulation: selecting specific lines/columns using awk and print CHARL0TTE Linux - Newbie 2 02-27-2010 02:40 AM
Can not capture no at end of file store it and print it using sed and awk amuthiga Programming 10 11-26-2008 07:37 AM
awk syntax to print particular record of xyz file? johnpaulodonnell Linux - Newbie 4 06-14-2007 07:47 AM
awk question - parsing xml file epoo Programming 7 01-24-2007 02:13 PM


All times are GMT -5. The time now is 08:09 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration