Quantcast
Channel: How to assign an input parameter for a function including awk? - Ask Ubuntu
Viewing all articles
Browse latest Browse all 2

How to assign an input parameter for a function including awk?

$
0
0

I am making some shortcuts for my account in a computation cluster. When I submit a job, the system assigns a job-ID (JOBID) to my calculation. To list all my calculations, I made an alias

alias j="queue -u myuser-ID"

which gives an output similar to

         JOBID     NAME     USER     ST       TIME 
      13716868   job_samp   myuserid  R    2:02:55     

Then the system creates a temporary directory with the name job.JOBID in which the output files are stored. To reach this directory, I wrote a function:

jj() { cd ~/many/many/files/job."$1"; }

which takes me to this temporary file with the command 'job JOBID'. To save some more keystrokes I want to write another function which takes the listed JOBID by my alias 'j' and take me to the temporary file. When I have just one job, the following function works

tt() { r=$(j | awk 'FNR>=2&&NR {print $1}'); jj $r; }

and command 'tt' takes me to that file. However, if I have more than one calculation (which is most of the case), the last function is useless since it will always take me to the first job listed. What I am trying to do is assign a variable to FNR bit of the 'tt' function so that when I type, let's say, 'tt 3' it will take me to the third job's directory. I tried using -v option as in

tt() { r=$(j | awk -v 'FNR=$2&&NR {print $1}'); jj $r; }

but I get an error saying 'FNR' is not a proper variable. How can I make this work ?

Thanks in advance!


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>