awk redirection


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk redirection
# 1  
Old 10-07-2010
awk redirection

Hi everyone

i am facing a very strange problem . see below is my code

#awk <do something> file 1 > file2


Now the problem is whenever i am redirecting the output to file2 it creates the file2 but of 0 size. i don't know what is the reason but it is very important to me to redirect the output .

please help me regarding this
# 2  
Old 10-07-2010
did you try like this?
Code:
# awk <do something> file > file2

# 3  
Old 10-07-2010
hi ygemici


yes i tried like this but still the file creating is of 0 bytes

---------- Post updated at 12:40 PM ---------- Previous update was at 12:37 PM ----------

and i am using sun solaris system and i don't knw why it is not running in my machine at office and i tried it at home also in linux machine and it is working fine so what could be the problem

---------- Post updated at 12:55 PM ---------- Previous update was at 12:40 PM ----------

please reply
# 4  
Old 10-07-2010
Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.
# 5  
Old 10-07-2010
can you write awk command?
# 6  
Old 10-07-2010
hi moderator
sry that will not happen again

hi the command is
Code:
#touch FSS-G-ABC-2010_22_22_2222_9.log

#cat >> FSS-G-ABC-2010_22_22_2222.log
abc def ghi 
jhg
^C
# for file in `ls *.log`
#>do
#>a=100
#>b=`echo $file  | cut -d_ -f4 | cut -d. -f1
#>c=`echo $file | sed "s/$b/$a/"
#>awk ' { if(NR==1) { $1="zzz" } ' $file > $c
#> rm $file
#> done

#> cat FSS-G-ABC-2010_22_22_100.log
#>


so here is my above code file which is created has nothing

Last edited by Franklin52; 10-08-2010 at 03:29 AM.. Reason: Please use code tags, thank you
# 7  
Old 10-07-2010
try like this but if awk statement does not match then your output file is empty
for exam if the nr 1 first val is not "zzz" in the *.log
and must not be forget close backquotes
and in your awk code second curly brackets is unnecessary

Code:
for file in `ls *.log`
do
a=100
b=`echo $file | cut -d_ -f4 | cut -d. -f1`
c=`echo $file | sed "s/$b/$a/"`
awk ' { if(NR==1)  $1="zzz" } ' $file > $c
rm $file
done



---------- Post updated at 10:20 PM ---------- Previous update was at 10:14 PM ----------

and if you tell clearly what you want to do then i can help you more than Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk file redirection issue

So I'm writing a script which tries to parse human-readable addresses. Part of it is this: print $2, implode(A,1,AN," "), CITY, PROV, POST, COUNTRY, CITYCOUNT>2; CITYCOUNT is a variable between 0 and 3 counting the number of words in a city name. I'm trying to prnt 1 wherever that's greater... (5 Replies)
Discussion started by: Corona688
5 Replies

2. UNIX for Dummies Questions & Answers

little problem of file redirection (awk)

I almost reach my objective (Youhouuu !!!!) But I really don't understand why it doesn't work until the end... :wall: For clarity's sake I am taking a very simple example. The operations I am doing in the script (gsub and print) really don't have any importance !!! I just matter about... (10 Replies)
Discussion started by: beca123456
10 Replies

3. UNIX for Dummies Questions & Answers

about different redirection

explain the redirections 1>, 2>, 3>, ..... and 1< ,2<,3<..... where we use these things thanks Thread moved from AIX forum (2 Replies)
Discussion started by: tsurendra
2 Replies

4. Shell Programming and Scripting

I/O redirection

Hello everyone,I'm reading a book and there's code fragment: exec 3>&1 ls -l 2>&1 >&3 3>&- | grep bad 3>&- exec 3>&- It says that the red part of that code does not close fd 3 but the green does close the fd 3.I can't understand that.....Why?Any predicate will be appreciated.:) (18 Replies)
Discussion started by: homeboy
18 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

Error with redirection in awk

I'm trying to find average of values in 2nd column in some files. Filenames have following pattern eg: tau_2.54_even_v1.xls tau_2.54_odd_v1.xls tau_1.60_v1.xls tau_800_v1.xls #!/bin/bash for file in pmb_mpi tau xhpl mpi_tile_io fftw ; do for f in "2.54" "1.60" "800" ;do if... (2 Replies)
Discussion started by: vishwamitra
2 Replies

7. Shell Programming and Scripting

awk print redirection to variable file name

Hello, i need to redirect the output of print to a variable file name: #This is normal awk '{ print $17 > "output.txt" }' input #I need something like this awk '{ print $17 > "output_${25}.txt" }' input how to format the output file name to contain a variable? (6 Replies)
Discussion started by: nazeeb
6 Replies

8. Shell Programming and Scripting

redirection

Hi, The code below works, it's a part of a bash shell script that serve to search a pattern $pattern_da_cercare in the files contained in a directory $directory_iniziale. Now the proble is: How can I redirect stderr to a file? PS: so I want to redirect ALL the errors to a file. I tryed... (9 Replies)
Discussion started by: DNAx86
9 Replies

9. Shell Programming and Scripting

awk two file redirection

Hi, i use awk -F to print three variable delimited by comma $1 $2 $3 if $2=="" i want to extract this information missing from another file using awk -v + some process. but the problem i can't use the two awk together cause of redirection there's a solution. note: i can't use another... (1 Reply)
Discussion started by: kamel.seg
1 Replies

10. Shell Programming and Scripting

Tail -f, awk and redirection

I want to run tail -f to continuously monitor a log file, outputing a specific field to a second log file. I can get the first portion to work with the following command: tail -f log | awk '{if ($1 == "Rough") print $5}' also: awk '{if ($1 == "Rough") print $5}' <(tail -f log) The... (2 Replies)
Discussion started by: mfajer
2 Replies
Login or Register to Ask a Question