TRICKY TASK USING AWK [message #92769] |
Fri, 26 February 2016 01:20  |
Sapna Mishra
Messages: 66 Registered: December 2015
|
Member |
|
|
Hello all,
What I have is:
IDL> i=1
IDL> $ awk -v var="$i" '{print $var}' tmp1.dat> tmp3.dat
Upto this it is working ok. now what I want:
IDL> fname[i]='QB0332_CHIP1_GRIS_600V_SCIENCE_SKY_SPECTRUM_FORS1. 2007_11_11T06_43_02.032redwave.dat'
IDL> $ awk -v var="$i" '{print $var}' fname[i]> fnameout[i]
Can I do it some how??? I found it most tricky. Basically can we use variables defined inside idl into shell commands.
Anyone know how to solve this tricky job???
|
|
|
Re: TRICKY TASK USING AWK [message #92772 is a reply to message #92769] |
Fri, 26 February 2016 04:03   |
dg86
Messages: 118 Registered: September 2012
|
Senior Member |
|
|
On Friday, February 26, 2016 at 4:20:20 AM UTC-5, Sapna Mishra wrote:
> Hello all,
>
> What I have is:
>
> IDL> i=1
> IDL> $ awk -v var="$i" '{print $var}' tmp1.dat> tmp3.dat
>
> Upto this it is working ok. now what I want:
>
> IDL> fname[i]='QB0332_CHIP1_GRIS_600V_SCIENCE_SKY_SPECTRUM_FORS1. 2007_11_11T06_43_02.032redwave.dat'
> IDL> $ awk -v var="$i" '{print $var}' fname[i]> fnameout[i]
>
> Can I do it some how??? I found it most tricky. Basically can we use variables defined inside idl into shell commands.
>
> Anyone know how to solve this tricky job???
Without delving too deeply into the details of your specific application, it sounds like
you want to build up a string containing the desired command, and then to use SPAWN to
execute that command. The general idea is
IDL> cmd = 'awk my_awk_command ' + fname[i] + ' > ' + fnameout[i]
IDL> spawn, cmd
Note that you'll have to be careful about the quotation marks in the IDL string
that I've called 'cmd'. To get this right, you'll have to read the documentation on
IDL strings, specifically how to escape special characters (such as quotation marks).
You can double-check that you've built up the command properly by printing the string:
IDL> print, cmd
This should print exactly the command that you'd like to execute.
Finally, you'll have to be careful to insert spaces between the substrings that make up
your command so that the result is syntactically correct for execution by the shell.
In my sketched solution, I've deliberately placed a space after the placeholder
pseudocode 'my_awk_command'.
All the best,
David
|
|
|
|
|
|
|
|
|
Re: TRICKY TASK USING AWK [message #92793 is a reply to message #92791] |
Mon, 29 February 2016 09:44   |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
On Monday, February 29, 2016 at 11:58:32 AM UTC-5, Sapna Mishra wrote:
> Actually I want to grep a particular column say column 2 from fname[i] and want to save it to fnameo[i] as an output. In IDL I don't know how to read any file having unknown numbers of columns because in READCOL to read file we need to mention a variable for each column in which particular column will get stored.
Here is a short IDL program to read the number of columns in a file, e.g.
ncol = findnumcol('myfile.dat')
function findnumcol, file
; Return the number of columns of data in a file
; Just reads the first line and assume rest of the file
; is the same. Could add code to skip header lines
openr,lun,file,/get_lun
st = ''
readf,lun,st
free_lun,lun
tmp = strsplit(st,count=ncol)
return,ncol
end
|
|
|
|
|
|
|
|
Re: TRICKY TASK USING AWK [message #92801 is a reply to message #92794] |
Tue, 01 March 2016 19:36  |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
READCOL does not care how many columns are in a file. Say a file "bigtable.dat' has 100 columns and we just want to read the 5th column. This would work.
IDL> readcol,'bigtable.dat',v5,f='x,x,x,x,f'
Unfortunately, one can't abbreviate the format as f = '4x,f' though this feature wouldn't be too hard to add.
On Tuesday, March 1, 2016 at 1:08:03 AM UTC-5, Sapna Mishra wrote:
Say If I have infinite number of columns And I want to read 100th column how would I do that, shall I need to give 100 parameters in Readcol?? This seems tough to me.
|
|
|