ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Hi everyone,
thanks bigearsbilly and muha for your help i've been able to generate happily input files w/o much efforts.
Now i was trying to modify the script to make an inverse operation, since N input files give me N output, and i wish to have all the results into a text file for importing in excel, what i want to do is this:
look inside N files one by one, find where is the tag "vals"
after the tag there will be 8 values, i should collect only the 3rd the 5th and 7th and put them into a text file separated by spaces.
Each file should be on a line.
a sample outup file is this kind
Code:
mcnp 5 07/06/07 02:03:49 101 10000000 150547532
c cell cards
ntal 1
18
tally 18 2 0
impulsi in un detector
f 1
2
d 1
u 0
s 0
m 0
c 0
et 4
3.00000E-02 8.34230E-01 8.35770E-01
t 0
vals
1.15955E-01 0.0009 1.10371E-01 0.0009 2.83826E-02 0.0019 2.54708E-01 0.0005
tfc 1 1 1 1 1 1 1 4 1
10000000 2.54708E-01 5.40931E-04 4.21937E+05
where the numbers i am interested in are in bold.
I was thinking in modifiying the script like this:
Code:
@ARGV = ($data_file);
@coords = <>; # slurp coordinates
warn "Is '$data_file' a proper coordinate file? It contains non-numerics\n"
if grep vals /[a-z]/i, @coords;
but i am pretty unsure is correct..
beside that i have no clue how to tell it to open multiple files..
if someone can help i will be very thankful!
Thanks
I always use @ARGV cos I am lazy.
@ARGV is a list, so if it's a list of files each is opened in turn
by the <> operator, the current file being in $ARGV
the linenumber in $. however is cumulative
thanks bigearsbilly,
but i think i need to change a bit the syntax of the grep..
if i send like that it just collect everything numeric on the file
while i want it to collect only the numbers that are under "vals"
moreover, i want it to have one output file, in this case it would have as many outputs as inputs..
Hello
no i didn't have much time to work on it, because i found some errors in my calculations and i needed to redo most of them it is a very time consuming process so i spent the last days changing radioactive sources every X minutes from the detector well, and constantly monitoring that everything was recorded correct. what a boring duty.
however, while i have almost made the grep vals part work (i think i have some more to learn on regex expressions)
i have no clue how to make it collect for example all the files on a dir, open them in sequence, find the "vars" collect the data
and store it in rows into a txt file ready for excel importing..
well, I have little to do today.
I'm willing to help out.
let me get it,
after vals there is a newline and then values on a line.
you need 3rd 5th and 7th
these need to be output to a .CSV or such like (I find tab delimited works better
importing to exel)
yes usually i need 3 5 and 7 value of the line after vals
but the number can vary (i think i can deal myself with that variation)
csv is perfect..
tab or semicolon will be working perfectly!
This is a one-liner that turns it into spaces:
It pretty ugly but i think it does the job.
All it does is print the line you are interested in. You could always remove the columns later. Better still would be to modify the sed to print out the right fields. Or use an |awk behind it.
It puts the file in the first field. Remove the last $i if you want to dump that info.
Code:
for i in *.txt;do sed ':a;$!N;s/\n//;ta;' $i |sed "s/.*vals/$i/g;s/tfc.*//g"; done
text2.txt 2.15955E-01 0.0009 1.10371E-01 0.0009 2.83826E-02 0.0019 2.54708E-01 0.0005
text.txt 1.15955E-01 0.0009 1.10371E-01 0.0009 2.83826E-02 0.0019 2.54708E-01 0.0005
With tabs instead of spaces:
Code:
for i in *.txt;do sed ':a;$!N;s/\n//;ta;' $i |sed "s/.*vals/$i/g;s/tfc.*//g;s/\s\{1,\}/\t/g"; done
text2.txt 2.15955E-01 0.0009 1.10371E-01 0.0009 2.83826E-02 0.0019 2.54708E-01 0.0005
text.txt 1.15955E-01 0.0009 1.10371E-01 0.0009 2.83826E-02 0.0019 2.54708E-01 0.0005
wow
for some odd reasons i didn't get the email notificating me i have new posts!
but thanks muha, i still need that, i will try it in a matter of day!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.