Welcome to iraf.net Sunday, May 19 2024 @ 09:02 PM GMT


 Forum Index > Help Desk > Applications New Topic Post Reply
 Help with simple scripting problem 2
   
Gaba_p
 04/08/2009 07:22PM (Read 2079 times)  
++++-
Regular Member

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!

 
Profile Email Website
 Quote
fitz
 04/08/2009 07:22PM  
AAAAA
Admin

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

 
Profile Email
 Quote
Gaba_p
 04/08/2009 07:22PM  
++++-
Regular Member

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!

 
Profile Email Website
 Quote
fitz
 04/08/2009 07:22PM  
AAAAA
Admin

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'

 
Profile Email
 Quote
Gaba_p
 04/08/2009 07:22PM  
++++-
Regular Member

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!

 
Profile Email Website
 Quote
   
Content generated in: 0.17 seconds
New Topic Post Reply

Normal Topic Normal Topic
Sticky Topic Sticky Topic
Locked Topic Locked Topic
New Post New Post
Sticky Topic W/ New Post Sticky Topic W/ New Post
Locked Topic W/ New Post Locked Topic W/ New Post
View Anonymous Posts 
Anonymous users can post 
Filtered HTML Allowed 
Censored Content 
dog allergies remedies cialis 20 mg chilblain remedies


Privacy Policy
Terms of Use

User Functions

Login