![]() |
hi friends,
how to use one awk within another awk..... i want to o actually...something like.... awk ' { if ( $1 == 1 ) awk ' { var=$1 }' 2ndfile }' 1stfile but this 2nd awk is not working..... it gives error...... my problem is ... that if the first field of 1stfile is 1 then only store the value of 2ndfile in var otherwise not... but i amnot able to get the ouput...... HELP ME OUT FRIENDS........... :( :( :( |
Quote:
I know doing the above is bad practice, though I can't think of anything to accomplish that. One thing I also noticed about your code is that you want to store a variable of one awk program as if it were from the mother awk that forked it, which wouldn't work. Also, this program is working in 'main' loop mode, which goes in the form while(<>), process line, which goes through every line. In this case, that would mean you're replacing 'var' every single time, which doesn't seem to be the desired result, though I may be wrong. I have actually been trying to work out this problem since I got home from school, and will be waiting for a better explanation and logic of what you want to do so I can help better. Hope to here from you soon... |
Thanx for ur reply....
ok ...i will explain my problem that what exactly i want.... i am basically writing a program for backup...of a particular directory , if it's size increased by 1024 bytes everytime. i have two files with me 1. flag 2. size initially flag has a value 0 prg will first read this file and if the value is 0 then it will take size of /dir through du command and store it in the file size. and also the value of flag file will change to 1. now the second time again flag file wll be readed and as now the value is changed to 1 so here the need arise to have the value from the size file and store it in a variable and then through some calculations compare it and judge that if the resultant value is greater than or equal to 1024 bytes than again du coomand should run and take the backup in a new file... so for thsi scenario i need awk command and off course need to store the value... so my code is something like... du -sb /home > size awk '{ if ( $1 == 0 ) { du -sb /home > newsize TAKE BACKUP echo 1 > flag } else { awk '{ var1=$1 }' size awk '{ var2=$1 }' newsize if ( (var1-var2) >= 1024 ) { TAKE BACKUP du -sb > newsize } } }' flag my code is not exactly same but something of this sort.... but here else part is not at all working... the problem i am facing is that awk with in another awk is not running , niether i am able to store the output of awk in any variable which i can use further..... i hope u understand my problem well.... pls guide me in a right direction..... TAKE CARE |
Not at a *nix terminal at the moment, but i'll work on it when I get home. Might want to reiterate the logic of the program, not code, k:
:
#!/bin/sh |
Thanx Buddy!
ur code really works.. Thank you very much for ur kind help..... ALL THE BEST TAKE CARE Regards |
| All times are GMT -5. The time now is 5:06 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC