Welcome to iraf.net Sunday, May 19 2024 @ 09:02 PM GMT
Gaba_p |
04/08/2009 07:22PM (Read 2079 times)
|
|
|
Status: offline
Registered: 10/10/2008
Posts: 104
|
Hi,I have a two column file like this:text1 text2
text3 text4
...and I want to access the first 'n' columns and print them to a file. I've tried this (among a bunch of other things, but this one seems to be the more reasonable one to me:for (i=1; i<=5; i+=1) {
fscan (filename, m1, m2)
print (m1, m2, >> output)
}I get an "undefined local variable 'm1' " (m1 and m2 are defined as string variables).Thanks!
|
|
|
|
fitz |
04/08/2009 07:22PM
|
|
|
Status: offline
Registered: 09/30/2005
Posts: 4040
|
See the FIELDS task, it'll let you select columns from a text file over a range of rows. The 'undefined variable' message likely means the scan into the variable failed, e.g. 'filename' isn't a struct variable or you read past the end of the input.-Mike
|
|
|
|
Gaba_p |
04/08/2009 07:22PM
|
|
|
Status: offline
Registered: 10/10/2008
Posts: 104
|
I'm sorry, I made a mistake. Where it says "and I want to access the first 'n' columns and print them to a file" it should say "and I want to access the first 'n' [b:2a4ad54b88]LINES[/b:2a4ad54b88] and print them to a file"Thanks again!
|
|
|
|
fitz |
04/08/2009 07:22PM
|
|
|
Status: offline
Registered: 09/30/2005
Posts: 4040
|
Try[code:1:f146704ff6]cl> fields myfile.txt "1,2" "1-5" > newfile.txt[/code:1:f146704ff6]Will write columns 1 and 2 from the first 5 lines to 'newfile.txt'
|
|
|
|
Gaba_p |
04/08/2009 07:22PM
|
|
|
Status: offline
Registered: 10/10/2008
Posts: 104
|
This is how I got it to work:cl> fields myfile.txt "1-2" lines="1-5" > newfile.txtThanks Mike!
|
|
|
|
| |
|
Content generated in: 0.17 seconds |
|