help with awk with changing parameters: TY


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help with awk with changing parameters: TY
# 8  
Old 11-28-2011
Yes, I don't think it will work as what you have posted in the first post.
Try this...
Code:
for ff in `seq 3 $nlpN`;
do
  val=( $(awk 'NR==ff {print $1" "$2" "$3" "$4}' ff=$ff p_walls.raw) )
  npc1[$ff]=${va[0]}
  npc2[$ff]=${va[1]}
  npc3[$ff]=${va[2]}
  npRs[$ff]=${va[3]}
done

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 9  
Old 11-28-2011
Quote:
Originally Posted by ahamed101
Yes, I don't think it will work as what you have posted in the first post.
Try this...
Code:
for ff in `seq 3 $nlpN`;
do
  val=( $(awk 'NR==ff {print $1" "$2" "$3" "$4}' ff=$ff p_walls.raw) )
  npc1[$ff]=${va[0]}
  npc2[$ff]=${va[1]}
  npc3[$ff]=${va[2]}
  npRs[$ff]=${va[3]}
done

--ahamed
second reply with same looks, guess thats the way.. but can i got a stet beyond and have the other way.. like what i found at another thread?Smilie
ls -ltra| awk '{ for (i=1;i<=NF;i++) { if ( i > 8 ) printf("%s ",$i) else printf("%s|",$i) } printf("\n") }'

Last edited by vbe; 11-28-2011 at 01:12 PM..
# 10  
Old 11-28-2011
What is it that you are actually looking for?... You asked to optimize your code, we did without losing the functionality. If your requirement is something else, please provide more clarity and if possible some input and expected output etc

Help us to Help you!
--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 11  
Old 11-28-2011
Power

Quote:
Originally Posted by ahamed101
What is it that you are actually looking for?... You asked to optimize your code, we did without losing the functionality. If your requirement is something else, please provide more clarity and if possible some input and expected output etc

Help us to Help you!
--ahamed

now im embarrassedSmilie yeah the code is optimized and i thank you a lot.. i just wanted to make it even faster by invoking awk just once per file..

the option provided is was faster already, but i'm greedy and i want to make it even faster.. Smilie



i wanted to open the file,
then
do the loops and the operations
then
close the file

i didnt wanna loop the awk command. that's why i wanted to have sth like (This is not the code, just grab a look at the syntax and order)
https://www.unix.com/shell-programmin...-question.html
Code:
awk '
{        for (i=1;i<=NF;i++) 
         {if ( i > 8 )
          printf("%s ",$i)                        
          else                            
          printf("%s|",$i) } 
          printf("\n") 
}'   p_walls.raw

once again ty!

the input is like

*.inp file is like
Code:
17,   3.22854114,  0.562598288,  0.384291202
     18,   2.96085286,  0.085116826,  0.285071939
     19,   3.40070796,   2.27838659,  0.302027524
     20,   3.20035744,  0.333615214,  0.262585849
     21,   2.85644341,  0.258691043,  0.369726121
     22,   3.73537922,    1.3267405,  0.295917094
     23,   3.69372559,   1.32601321,  0.306054831
     24,   3.28857207,   0.63199228,  0.378117412
     25,   3.27523994,  0.695856452,  0.377585977

*.dat file is like
Code:
      25169     -3.8128E-09  3.7586E-10  6.3384E-08 
      25170     -3.8339E-09  3.7958E-10  6.3555E-08 
      25171     -3.8549E-09  3.8382E-10  6.3723E-08 
      25172     -3.8757E-09  3.8828E-10  6.3888E-08 
      25173     -3.8965E-09  3.9323E-10  6.4049E-08 
      25174     -3.9173E-09  3.9872E-10  6.4207E-08 
      25175     -3.9384E-09  4.0454E-10  6.4363E-08


and theres no output atm.. im assigning vars with this code Smilie

the problem is.. my loop is 100k+ passes long

and i have this:
Code:
...
for f in `seq $nlinpE $loopE`; 
do 
    dataI=`awk 'NR=='$f' { print  $2, $3, $4; exit }' aoa_5.inp` ;
        #echo $ff
    noD1[$f]=`echo "$dataI" | cut -f1 -d ','`; #echo ${noD1[$f]}    
    noD1i[$f]=`echo "$nlinpN1 + ${noD1[$f]}"|bc -l`;     
    noD1f[$f]=`echo "$nlDat1 + ${noD1[$f]}"|bc -l`;    
    
    dataIi=`awk 'NR=='${noD1i[$f]}' { print  $2, $3, $4; exit }' aoa_5.inp`    ;
    n1c1[$f]=`echo "$dataIi" | cut -f1 -d ' , '`;#
    n1c2[$f]=`echo "$dataIi" | cut -f2 -d ', '`;#
    n1c3[$f]=`echo "$dataIi" | cut -f3 -d ' ,'`;#
    dataDi=`awk 'NR=='${noD1f[$f]}' { print  $2, $3, $4; exit }' aoa_5.dat`;
    n1u1[$f]=`echo "$dataDi" | cut -f1 -d ' '| sed 's/E+/*10^/;s/E/*10^/';`;
    n1u2[$f]=`echo "$dataDi" | cut -f2 -d ' '| sed 's/E+/*10^/;s/E/*10^/';`;
    n1u3[$f]=`echo "$dataDi" | cut -f3 -d ' '| sed 's/E+/*10^/;s/E/*10^/';`;
    
    noD2[$f]=`echo "$dataI" | cut -f2 -d ','`; #
    noD2i[$f]=`echo "$nlinpN1 + ${noD2[$f]} "|bc -l`;    
    noD2f[$f]=`echo "$nlDat1 + ${noD2[$f]} "|bc -l`;    
    
    dataIii=`awk 'NR=='${noD2i[$f]}' { print  $2, $3, $4; exit }' aoa_5.inp` ;
    n2c1[$f]=`echo "$dataIii" | cut -f1 -d ', '`;
    n2c2[$f]=`echo "$dataIii" | cut -f2 -d ', '`;
    n2c3[$f]=`echo "$dataIii" | cut -f3 -d ' ,'`;

    dataDii=`awk 'NR=='${noD2f[$f]}' { print  $2, $3, $4; exit }' aoa_5.dat`;
    n2u1[$f]=`echo "$dataDi" | cut -f1 -d ' '| sed 's/E+/*10^/;s/E/*10^/';`;
    n2u2[$f]=`echo "$dataDi" | cut -f1 -d ' '| sed 's/E+/*10^/;s/E/*10^/';`;
    n2u3[$f]=`echo "$dataDi" | cut -f1 -d ' '| sed 's/E+/*10^/;s/E/*10^/';`;

    noD3[$f]=`echo "$dataI" | cut -f3 -d ','`; 
    noD3i[$f]=`echo "$nlinpN1 + ${noD3[$f]} "|bc -l`;    
    noD3f[$f]=`echo "$nlDat1 + ${noD3[$f]} "|bc -l`;    

    dataIiii=`awk 'NR=='${noD3i[$f]}' { print  $2, $3, $4; exit }' aoa_5.inp`;
    n3c1[$f]=`echo "$dataIiii" | cut -f1 -d ', '`;
    n3c2[$f]=`echo "$dataIiii" | cut -f2 -d ' ,'`;
    n3c3[$f]=`echo "$dataIiii" | cut -f3 -d ' ,'`;

    dataDiii=`awk 'NR=='${noD3f[$f]}' { print  $2, $3, $4; exit }' aoa_5.dat`;
    n3u1[$f]=`echo "$dataDiii" | cut -f1 -d ' '| sed 's/E+/*10^/;s/E/*10^/';`;
    n3u2[$f]=`echo "$dataDiii" | cut -f2 -d ' '| sed 's/E+/*10^/;s/E/*10^/';`;
    n3u3[$f]=`echo "$dataDiii" | cut -f3 -d ' '| sed 's/E+/*10^/;s/E/*10^/';`;
echo $f
done

i'm opening each one of the 2 file 4 times... thats time consuming... can any warlock around make it so that i open each file just once? i'm digging but i rly dont have that much time... yeah we always w8 til last minute :P i believe i may eventually come up with sth.. but i thought i could ask you guys this

once again.. thx.. this forum is rly alive! Smilie)

---------- Post updated at 02:24 PM ---------- Previous update was at 12:25 PM ----------

i am looking 4 sth similar to:

Code:
awk '{
        dataI=''NR=='$f' { print  $2 $3 $4; exit } ''
		
      	noD1[$f]=`echo "$dataI" | cut -f1 -d ','`;
	noD1i[$f]=`echo "$nlinpN1 + ${noD1[$f]}"|bc -l`; 
	dataIi=''NR=='${noD1i[$f]}' { print  $2 $3 $4; exit }''
	
	noD2[$f]=`echo "$dataI" | cut -f2 -d ','`; 
	noD2i[$f]=`echo "$nlinpN1 + ${noD2[$f]} "|bc -l`;
	dataIii=''NR=='${noD2i[$f]}' { print  $2 $3 $4; exit }''	
	
	noD3[$f]=`echo "$dataI" | cut -f3 -d ','`; 
	noD3i[$f]=`echo "$nlinpN1 + ${noD3[$f]} "|bc -l`;
	dataIiii=''NR=='${noD3i[$f]}' { print  $2 $3 $4; exit }''	
	}' <aoa_5.inp;

so far im trying to debug thou im not sure ill get somewhereSmilie

---------- Post updated at 04:38 PM ---------- Previous update was at 02:24 PM ----------

or maybe sth like this,,,

Code:
       awk  '  
	    
	'$f'  {
                dataI2[$f] = $2;
		dataI3[$f] = $3;
		dataI4[$f] = $4;
		noD1[$f] = $dataI1[$f];
		noD2[$f] = $dataI2[$f];
		noD3[$f] = $dataI3[$f];
		noD1i[$f] = $nlinpN1 + $dataI1[$f];
		noD2i[$f] = $nlinpN1 + $dataI2[$f];
		noD3i[$f] = $nlinpN1 + $dataI3[$f];
		}	
	'${noD1i[$f]}' { 
		dataIi2[$f]=$2;
		dataIi3[$f]=$3;
		dataIi4[$f]=$4;
		}
     
	'${noD2i[$f]}'	{ 
		dataIii2[$f]=$2;
		dataIii3[$f]=$3;
		dataIii4[$f]=$4;
		}
		
	'${noD2i[$f]}'	{ 
		dataIiii2[$f]=$2;
		dataIiii3[$f]=$3;
		dataIiii4[$f]=$4;
		}
			          
	' <aoa_5.inp;

any1?

Last edited by calim_cfd; 11-28-2011 at 06:52 PM.. Reason: adding html, cleaning, addin input
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pass Parameters to awk command

I need to pass values at runtime for the below awk command where l is the length and partial.txt is the file name. awk -v l=285 '{s="%-"l"s\n";printf(s,$0);}' partial.txt > temp1.txt; (5 Replies)
Discussion started by: Amrutha24
5 Replies

2. HP-UX

Changing Dynamic Tunable parameters in the kernel

To fix an "issue" we're having I need to update SHMMAX from 1GB to 2Gb, it's a dynamic parameter so am just wondering how flexible it really is. As Oracle is running on the server do I need to shut that down to change the parameter or will it just take the change on the fly? Also how would I... (6 Replies)
Discussion started by: Turlock
6 Replies

3. Shell Programming and Scripting

Search parameters on file with AWK

Hello everyone!! I need help with this please: I have a file with this content: 56977964333 730030201857822 1 2 4 56976969284 730030201412442 1 2... (3 Replies)
Discussion started by: bobbasystem
3 Replies

4. Shell Programming and Scripting

Help with explanation of awk parameters

Hello, Would someone be able to tell me exactly how this command works please? awk '!x++' As usual any help much appreciated (8 Replies)
Discussion started by: Grueben
8 Replies

5. Shell Programming and Scripting

passing parameters using awk

Hi, The below script is working fine awk1.sh ======= awk BEGIN { FS="|" } FNR==NR { f1=$2; next } $1 in f1 && $2 =="xx" && $1 == "DAILY_JOB" {print $3} awk -f awk1.sh a.txt b.txt--Its working fine . When passing parameters its not working .Any help it should be appereciated. ... (4 Replies)
Discussion started by: akil
4 Replies

6. Shell Programming and Scripting

awk parameters check

Is there a way to preform check if the parameters that was send with the command awk -f `file_name.awk` `input_file` before even it gets to the BEGIN section (i have tested a try to check in the BEGIN it doesn't let ,you must make it on the section that after the BEGIN) and then decide if the... (1 Reply)
Discussion started by: tal
1 Replies

7. Shell Programming and Scripting

AWK alias with parameters

Hello, How can I make an alias of an AWK one liner that prints specific lines from a file like below? # from a command like this: awk 'NR == 100, NR == 150' file.cfg The alias I want to make should work like this(I guess): <alias_command> <file.cfg><start_line><end_line> So the... (1 Reply)
Discussion started by: majormark
1 Replies

8. Shell Programming and Scripting

How to pass parameters to an awk file?

I have an awk file where I need to pass a filename and a value as a parameter from a sh script. I need to know how to pass those values in the sh script and how to use the same in the awk file. Thanks in advance!!! Geetha (3 Replies)
Discussion started by: iamgeethuj
3 Replies

9. Shell Programming and Scripting

awk - printing parameters

Hello I've got a script that takes 2 parameters. id and f. id is a user id and f is a file. I want to print this id on the first line and then the file. how can this be done? thanks (3 Replies)
Discussion started by: jacma
3 Replies

10. UNIX for Dummies Questions & Answers

Changing TCP parameters in solaris10

Hi I have to change some TCP settings in Solaris10 machine running on AMD. Is there any tool or GUI to do this. I want to see if there is any easy way to put them in the startup scripts. Thanks (1 Reply)
Discussion started by: sssow
1 Replies
Login or Register to Ask a Question