taking the output of awk command to a new file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers taking the output of awk command to a new file
# 1  
Old 08-01-2012
Java taking the output of awk command to a new file

Code:
cat doc | nawk -v da="${date}" '$23>199 {print $0 > "doc"+da+".txt"}'

Every time(need to run every day) i run this, i want to a create a new file "doc_01 Aug.txt".

Basically, i want to create a new file with date appended in it.

The above command is creating a file with name "0".
SmilieSmilie
Need help!!

Last edited by Scott; 08-01-2012 at 09:03 AM.. Reason: Code tags
# 2  
Old 08-01-2012
Code:
 
nawk -v da="${date}" '{fname="doc"da".txt"} $23>199 {print $0 > fname}'  doc

# 3  
Old 08-01-2012
I am working on unix box.

Code:
nawk -v da="${date}" '{fname="doc"da".txt"} $23>199 {print $0 > fname}'  doc

it is throwing a error
Code:
nawk : can't open file 1


Last edited by Scott; 08-01-2012 at 09:03 AM.. Reason: Code tags
# 4  
Old 08-01-2012
Code:
 
$ cat doc
234
234
234
23
4454
453
23
423
42
42
234234
2342

$ nawk -v da="20120801" '{fname="doc"da".txt"} $0>234{print $0 > fname}' doc                                                                        

$ cat doc20120801.txt 
4454
453
423
234234
2342

what is your date variable value ?

Code:
 
echo ${date}

This User Gave Thanks to itkamaraj For This Post:
# 5  
Old 08-01-2012
I am able to work it out.
i think it was not working cause date command output also contains spaces. It was having trouble creating a filename with spaces.
This User Gave Thanks to vagar11 For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert title as output of command to appended file if no output from command

I am using UNIX to create a script on our system. I have setup my commands to append their output to an outage file. However, some of the commands return no output and so I would like something to take their place. What I need The following command is placed at the prompt: TICLI... (4 Replies)
Discussion started by: jbrass
4 Replies

2. Shell Programming and Scripting

awk command line arguments not taking

# more minusf.awk #!/bin/awk -f BEGIN { FS=":"; } { if ( $2 == "" ) { print $1 ": no password!"; } } # ./minusf.awk aa aa aa aa awk: can't open aa (6 Replies)
Discussion started by: sri.phani
6 Replies

3. Solaris

No output from awk command

Hi all, In my SunOS 5.10, the command awk using BEGIN option doesn't print output variables like expected here is my test: with the following code everything is alright ps -eo pcpu,args | grep "httpd" | awk ' { print $1 } ' the result is 0.1 However, with this command ps -eo... (3 Replies)
Discussion started by: Elmassimo
3 Replies

4. Red Hat

Command understanding the output file destination in case of standard output!!!!!

I ran the following command. cat abc.c > abc.c I got message the following message from command cat: cat: abc.c : input file is same as the output file How the command came to know of the destination file name as the command is sending output to standard file. (3 Replies)
Discussion started by: ravisingh
3 Replies

5. Shell Programming and Scripting

Help needed with file output awk sed command - please

Hi I have a file that contains lines starting with a particular string plus a Colon: I need to output all these lines but only what comes after the colon Can you pelase assist? Example of lines in the file: com.ubs.f35.cashequities/cashequities: 1 2 ... (5 Replies)
Discussion started by: mnassiri
5 Replies

6. 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

7. Shell Programming and Scripting

awk command : To print the output to a file

half of the problem is already solved with the help of bartus11 suggestion I have a txt file having rows and coulmns, i want to perform some operation on a specific coulmn starting from a specific line. 50.000000 1 1 1 1000.00000 1000.00000 ... (5 Replies)
Discussion started by: shashi792
5 Replies

8. Emergency UNIX and Linux Support

getting wrong output with AWK command!!!

i have a file which gets appended with 9 records daily and the file keeps growing from then...i use to store the previous day files count in a variable called oldfilecount and current files count as newfilecount.my requirement is that i need to start processing only the new records from the... (3 Replies)
Discussion started by: ganesh_248
3 Replies

9. Shell Programming and Scripting

taking output in csv file from perl

Hi, I am new to perl I need to connect from linux server to oracle database and i need to query the database and take result into csv file. i try to do but i am getting this error: #!/usr/bin/perl use DBI; BEGIN { $ENV{ORACLE_HOME} = '/home/oracle/product/8.1.7'; ... (1 Reply)
Discussion started by: prakash.gr
1 Replies
Login or Register to Ask a Question