AWK Output to file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK Output to file.
# 1  
Old 11-09-2009
AWK Output to file.

I have this awk instructions:

#Interface with description
awk '/hostname/{a=$0} /interface/{b=$0} /address/{print a b $0}' informe-router.txt
awk '/interface/{b=$0} /address/{c=$0} /description/{print b c $0}' informe-router.txt
awk '/router/,/network/{print $0}' informe-router.txt

and I need all output to a file, but if I do this:

awk '/hostname/{a=$0} /interface/{b=$0} /address/{print a b $0}' informe-router.txt > output.txt
awk '/interface/{b=$0} /address/{c=$0} /description/{print b c $0}' informe-router.txt > output.txt
awk '/router/,/network/{print $0}' informe-router.txt > output.txt

take de output for the last instruction, and I need all output.

Thanks for all Smilie.
# 2  
Old 11-09-2009
Code:
awk '/hostname/{a=$0} /interface/{b=$0} /address/{print a b $0}' informe-router.txt > output.txt
awk '/interface/{b=$0} /address/{c=$0} /description/{print b c $0}' informe-router.txt >> output.txt
awk '/router/,/network/{print $0}' informe-router.txt >> output.txt

You can also try to do all the work in a single awk script.

Jean-Pierre.
# 3  
Old 11-09-2009
Quote:
Originally Posted by aigles
Code:
awk '/hostname/{a=$0} /interface/{b=$0} /address/{print a b $0}' informe-router.txt > output.txt
awk '/interface/{b=$0} /address/{c=$0} /description/{print b c $0}' informe-router.txt >> output.txt
awk '/router/,/network/{print $0}' informe-router.txt >> output.txt

You can also try to do all the work in a single awk script.

Jean-Pierre.
Thanks for all!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to reformat output if input file is empty, but not if file has data in it

The below awk improved bu @MadeInGermany, works great as long as the input file has data in it in the below format: input chrX 25031028 25031925 chrX:25031028-25031925 ARX 631 18 chrX 25031028 25031925 chrX:25031028-25031925 ARX 632 14... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. UNIX for Dummies Questions & Answers

awk - Rename output file, after processing, same as input file

I have one input file ABC.txt and one output DEF.txt. After the ABC is processed and created output, I want to rename ABC.txt to ABC.orig and DEF to ABC.txt. Currently when I am doing this, it does not process the input file as it cannot read and write to the same file. How can I achieve this? ... (12 Replies)
Discussion started by: High-T
12 Replies

3. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

4. Shell Programming and Scripting

AWK Script to convert input file(s) to output file

Hi All, I am hoping someone can help me with some scripting I need to complete using AWK. I'm trying to process multiple fixed files to generate one concatenated fixed file in a standard format. The Input file is:- aaaa bbbbb ccccc 1 xxxx aaa bbb aaaa bbbbb ccccc 2 abcd aaa CCC... (9 Replies)
Discussion started by: jason_v_brown
9 Replies

5. Shell Programming and Scripting

awk output redirection to file

I have a system stat command running which generates data after 5 sec or so. I pass this data to awk and do some calculation to present the data differently. Once done now I want to pass this data to file as and when generated but doesn't work..unless the first command completes successfully.... (6 Replies)
Discussion started by: learnscript
6 Replies

6. Shell Programming and Scripting

Using awk to when reading a file to search and output to file

Hi, I am not sure if this will work or not. I am getting a syntax error. I am reading fileA, using an acct number field trying to see if it exists in fileB and output to new file. Can anyone tell me if what I am doing will work or should I attempt it another way? Thanks. exec < "${fileA}... (4 Replies)
Discussion started by: ski
4 Replies

7. Shell Programming and Scripting

Parse file using awk and work in awk output

hi guys, i want to parse a file using public function, the file contain raw data in the below format i want to get the output like this to load it to Oracle DB MARWA1,BSS:26,1,3,0,0,0,0,0.00,22,22,22.00 MARWA2,BSS:26,1,3,0,0,0,0,0.00,22,22,22.00 this the file raw format: Number of... (6 Replies)
Discussion started by: dagigg
6 Replies

8. Shell Programming and Scripting

Awk output to file in IF statement

Hi all, I currently have the following script in 1) which outputs to a file if the 3rd column is equal to the message_id value. This works. However what I want to do is incorporate an else statement and output to a different file if the 3rd column doesnt equal the message_id values. I tried that... (7 Replies)
Discussion started by: Donkey25
7 Replies

9. Shell Programming and Scripting

awk output to file

Hello I used awk on a file to created a new field. I used >> to redirect the output to a file but, it went to the screen instead of the file. Is there a way to redirect awk to a file? Here is what I am trying to do: join $s $t | awk '{total = $2 - $3};{print $1, $2, $3, total}' >> $r Any... (2 Replies)
Discussion started by: stonemonolith
2 Replies

10. Shell Programming and Scripting

awk - output to file

How do I make my awk script write its output to a file? (3 Replies)
Discussion started by: owijust
3 Replies
Login or Register to Ask a Question