Help with simple scripting problem 2
Gabriel wrote on Apr 08, 2009
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!
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!
Mike Fitzpatrick wrote on Apr 08, 2009
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
-Mike
Gabriel wrote on Apr 08, 2009
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' LINES and print them to a file"
Thanks again!
Thanks again!
Mike Fitzpatrick wrote on Apr 08, 2009
Try
Will write columns 1 and 2 from the first 5 lines to 'newfile.txt'
cl> fields myfile.txt "1,2" "1-5" > newfile.txtWill write columns 1 and 2 from the first 5 lines to 'newfile.txt'
Gabriel wrote on Apr 08, 2009
This is how I got it to work:
cl> fields myfile.txt "1-2" lines="1-5" > newfile.txt
Thanks Mike!
cl> fields myfile.txt "1-2" lines="1-5" > newfile.txt
Thanks Mike!
Last post on Apr 08, 2009