LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 07-12-2007, 06:15 AM   #16
assasukasse
Member
 
Registered: Mar 2006
Location: UK
Distribution: Debian, Ubuntu
Posts: 129

Original Poster
Rep: Reputation: 15

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
 
Old 07-12-2007, 06:22 AM   #17
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,314

Rep: Reputation: 175Reputation: 175
multiple files, easy.

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

@ARGV = qw( this_file that_file ... )

of course there is a glob

@ARGV = <*.txt> for instance
 
Old 07-12-2007, 06:23 AM   #18
writing
LQ Newbie
 
Registered: Jul 2007
Posts: 1

Rep: Reputation: 0
good one...
 
Old 07-12-2007, 11:15 AM   #19
assasukasse
Member
 
Registered: Mar 2006
Location: UK
Distribution: Debian, Ubuntu
Posts: 129

Original Poster
Rep: Reputation: 15
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..
 
Old 07-16-2007, 03:16 AM   #20
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,314

Rep: Reputation: 175Reputation: 175
have you done it?
it's relatively easy.
 
Old 07-18-2007, 03:43 AM   #21
assasukasse
Member
 
Registered: Mar 2006
Location: UK
Distribution: Debian, Ubuntu
Posts: 129

Original Poster
Rep: Reputation: 15
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..
 
Old 07-18-2007, 03:47 AM   #22
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,314

Rep: Reputation: 175Reputation: 175
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)
 
Old 07-18-2007, 02:39 PM   #23
assasukasse
Member
 
Registered: Mar 2006
Location: UK
Distribution: Debian, Ubuntu
Posts: 129

Original Poster
Rep: Reputation: 15
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!
 
Old 07-30-2007, 04:51 PM   #24
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 37
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
 
Old 09-15-2007, 01:07 PM   #25
assasukasse
Member
 
Registered: Mar 2006
Location: UK
Distribution: Debian, Ubuntu
Posts: 129

Original Poster
Rep: Reputation: 15
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!
 
  


Reply

Tags
automated, edit, file, script, text


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need aid with static IP Zmyrgel Linux - Networking 9 06-25-2006 07:59 AM
Aid me recover from reboot. Zmyrgel Slackware 1 05-11-2006 04:01 AM
Xandros internet aid Gavin19 Linux - Newbie 0 09-23-2004 04:54 PM
Linux Webserver Aid. HaTHor Linux - Networking 2 10-23-2003 02:56 PM
Looking for software to aid in writing my own o/s ChimpFace9000 Linux - Software 4 09-11-2002 07:16 PM


All times are GMT -5. The time now is 08:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration