output 2 files using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting output 2 files using awk
# 1  
Old 02-09-2011
output 2 files using awk

Hi guys,

Basically, I have an END {print NR} statement in my awk script to count the number of records as I have concatenated multiple files. But instead of generating this total number of records to the same output data file. I want to put this in a separate control file using the same awk script.

How can this be done? Can I specify a separate output file for this END {print NR} statement for the same awk script?

Thanks!
# 2  
Old 02-09-2011
Try this,
Code:
END {print NR > "recno.out"}

This User Gave Thanks to pravin27 For This Post:
# 3  
Old 02-09-2011
thanks dude!!!!
# 4  
Old 02-14-2011
Code:
END {print NR > "recno.out"}

What if I want to parameterize this output file from print NR? I can't seem to make it work.. anyone?
Code:
BusDt=2011-02-14
awk -v BusDt="$BusDt" -F"|" '{print $0 FILENAME} END {print NR > "$BusDt.ctl"}' SOURCE/*.pretxt > ${BusDt}.txt

It's writing to $BusDt.ctl instead of 2011-02-14.ctl

Last edited by Franklin52; 02-14-2011 at 05:05 AM.. Reason: Please use code tags, thank you
# 5  
Old 02-14-2011
Try this,
Code:
awk -v BusDt="$BusDt" -F"|" '{print $0 FILENAME} END {print NR > BusDt".ctl"}' SOURCE/*.pretxt > ${BusDt}.txt

This User Gave Thanks to pravin27 For This Post:
# 6  
Old 02-14-2011
man, thank you again! please keep on checking my posts.. I'd really be needing your help Smilie all the best Smilie
# 7  
Old 02-14-2011
awk -v BusDt="$BusDt" -F"|" '{print $0 FILENAME} END {print NR > "'$BusDt'.ctl"}' SOURCE/*.pretxt > ${BusDt}.txt


use the above command...

Last edited by rajesh_pola; 02-14-2011 at 06:28 AM.. Reason: spelling mistake
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk output different between two files

The awk below when run using the contents of file, works great with the desired output of expName barcodeSampleInfo barcodedSamples . However, when the complete file is used (attached) I get different output. It looks like the same data is there but the ordering is off. Both data sets are... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Shell Programming and Scripting

Using awk to output matches between two files to one file and mismatches to two others

I am trying to output the matches between $1 of file1 to $3 of file2 into a new file match. I am also wanting to output the mismatches between those same 2 files and fields to two separate new files called missing from file1 and missing from file2. The input files are tab-delimited, but the... (9 Replies)
Discussion started by: cmccabe
9 Replies

3. Shell Programming and Scripting

Remove lines from output in files using awk

I have two large files (~250GB) that I am trying to remove the where GT: 0/0 or 1/1 or 2/2 for both files. I was going to use a bash with the below awk, which I think will find each line but how do I remove that line is that condition is found? Thank you :). Input 20 60055 . A ... (4 Replies)
Discussion started by: cmccabe
4 Replies

4. Shell Programming and Scripting

Using awk and output to files

I currently have this code: awk ' BEGIN { FS = OFS = "|"} { l=length($1) $1 = sprintf("%s-%s-%s %s:%s:%s", substr($1, l - 13, 4), substr($1, l - 9, 2), substr($1, l - 7, 2), substr($1, l - 5, 2), substr($1, l - 3, 2), substr($1, l - 1)) print }' infile exit Lets say I also wanted to modify $11... (4 Replies)
Discussion started by: LDHB2012
4 Replies

5. Shell Programming and Scripting

awk: too many output files created from while loop

I am using awk to read lines from a CSV file then put data into other files. These other files are named using the value of a certain column. Column 7 is a name such as "att" or "charter" . I want to end up with file names with the value of column 7 appended to them, like this: ... (5 Replies)
Discussion started by: dodgerfan78
5 Replies

6. Shell Programming and Scripting

Compare two files and output difference, by first field using awk.

It seems like a common task, but I haven't been able to find the solution. vitallog.txt 1310,John,Hancock 13211,Steven,Mills 122,Jane,Doe 138,Thoms,Doe 1500,Micheal,May vitalinfo.txt 12122,Jane,Thomas 122,Janes,Does 123,Paul,Kite **OUTPUT** vitalfiltered.txt 12122,Jane,Thomas... (2 Replies)
Discussion started by: charles33
2 Replies

7. UNIX for Dummies Questions & Answers

df -> output files; comparison using awk or...

:wall: I am trying to do the following using awk (is that the best way?): Read 2 files created from the output of df (say, on different days) and compare the entries using the 1st (FileSys) and 6th (Mount) fields to see if the size has changed. Output (at least), to a new file (some header... (2 Replies)
Discussion started by: renata
2 Replies

8. Shell Programming and Scripting

AWK Compare files, different fields, output

Hi All, Looking for a quick AWK script to output some differences between two files. FILE1 device1 1.1.1.1 PINGS device1 2.2.2.2 PINGS FILE2 2862 SITE1 device1-prod 1.1.1.1 icmp - 0 ... (4 Replies)
Discussion started by: stacky69
4 Replies

9. Shell Programming and Scripting

Redirecting to different output files with awk.

Well, it didn't take me long to get stumped again. I assure you that I'm not mentally deficient, just new to scripting. So, here's the gist. I want to redirect output from awk based off of which branch of an if-else statement under which it falls. #!/bin/bash #some variables... (2 Replies)
Discussion started by: mikesimone
2 Replies

10. Shell Programming and Scripting

Writing output into different files while processing file using AWK

Hi, I am trying to do the following using AWK program. 1. Read the input data file 2. Parse the record and see if it contains errors 3. If the record contains errors, then write it into Reject file, else, write into usual output file or display it on the screen Here is what I have done -... (6 Replies)
Discussion started by: vidyak
6 Replies
Login or Register to Ask a Question