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

did you try like this?

# awk <do something> file > file2

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

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.

can you write awk command?

hi moderator
sry that will not happen again

hi the command is

#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

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

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 :slight_smile:

hi ygemici

thanx for ur reply i will try this thing tomorrow

but the thing is in my file $1 exits in my $file and i need to replace it with some variable that's y i added this
but seriously output file is getting generated but not the content
i tried many times but still not output is there any alternative way to use beside awk i think sed also do it

sed "s/\(.*_\)\(....\)\(.*$\)/\1$a\3/" $file > $c

even this is not working
don't know what is not working and why output file is having no records

nawk 'FNR==1 {$1="zzz"}1' $file > $c

can you write a sample input file?

hi everyone in my previous post i wrote one command

#>awk ' { if(NR==1) { $1="zzz" } ' $file > $c

and i was saying file c is created with 0 sixe now i understand why it is creating 0 sixe
see the problem is if u r using awk and redirecting the output u must use

#>awk ' { if(NR==1) { $1="zzz";print } ' $file > $c

print statment then only it will write .

it works :slight_smile:

thankx everyone who helped me in this

good works to you..
and you can use instead of the code

a=100
b=`echo $file  | cut -d_ -f4 | cut -d. -f1
c=`echo $file | sed "s/$b/$a/"

to

c=`echo $file | sed 's/\(.*\)_[0-9][0-9][0-9][0-9]\(_*[0-9]*\)/\1_100\2/'`

regards
ygemici