need help with a bash script

need help with a bash script

am 19.09.2006 21:13:55 von Fabio Zyserman

Hi all,

sorry if this is not the appropriate list to post my question,
but surely more than one guru here will be able to
guide me in my modest quest.

Here is my problem:


I have a lot of data files, which differ in their name by a number,
for example:
data-theta=0-np=1.2
data-theta=0-np=1.3
data-theta=0-np=1.4,
....and so on.

All files have the same structure (same number of columns and lines);
each single entry is a real number in free exp format, i.e. it looks
like this:
0.1224e01, but it is not important, I think

What I want to do is to create a new file, with one line from each of the
data files (say, line beginning with 0.01e00), adding to each line in
the new file the number appearing in the name of the corresponding data
file.
That is, the new file will contain one more column than the original
ones; the new
file would be
0.01e00 .... .... .... 1.2
0.01e00 .... .... .... 1.3
0.01e00 .... .... .... 1.4
..
..
Hope you can help!!!!

Many Thanks in advance!

Fabio Zyserman

-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: need help with a bash script

am 19.09.2006 21:44:59 von office

Fabio Zyserman wrote:
> What I want to do is to create a new file, with one line from each of the
> data files (say, line beginning with 0.01e00), adding to each line in
> the new file the number appearing in the name of the corresponding data
> file.
> That is, the new file will contain one more column than the original
> ones; the new
> file would be
> 0.01e00 .... .... .... 1.2
> 0.01e00 .... .... .... 1.3
> 0.01e00 .... .... .... 1.4

rm -f newfile
for i in `ls data-*`
do
ls $i
printf `cat "$i" | grep -i "0.01e00"` >> newfile
printf ".........." >> newfile
printf `basename $i | cut -d = -f 3` >> newfile
printf "\n" >> newfile
done


well.. you get the idea.

--Adrian.
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

Re: need help with a bash script

am 19.09.2006 21:53:51 von Brett Zimmerman

On Tue, 19 Sep 2006, Fabio Zyserman wrote:

> Hi all,
>
> sorry if this is not the appropriate list to post my question,
> but surely more than one guru here will be able to
> guide me in my modest quest.
>
> Here is my problem:
>
>
> I have a lot of data files, which differ in their name by a number,
> for example:
> data-theta=0-np=1.2
> data-theta=0-np=1.3
> data-theta=0-np=1.4,
> ...and so on.
>
> All files have the same structure (same number of columns and lines);
> each single entry is a real number in free exp format, i.e. it looks
> like this:
> 0.1224e01, but it is not important, I think
>
> What I want to do is to create a new file, with one line from each of the
> data files (say, line beginning with 0.01e00), adding to each line in
> the new file the number appearing in the name of the corresponding data
> file.
> That is, the new file will contain one more column than the original
> ones; the new
> file would be
> 0.01e00 .... .... .... 1.2
> 0.01e00 .... .... .... 1.3
> 0.01e00 .... .... .... 1.4
> .
> .
> Hope you can help!!!!
>
> Many Thanks in advance!
>

You probably want something along these lines:

#!/bin/bash

for file in `ls|grep data-theta`;
do
number=$(echo $file|awk -F '=' '{print $3}');
line=$(grep '0.01e00' $file);
echo $line $number;
done;

Hope that helps.

-bz

--
Brett Zimmerman
zim@oscer.ou.edu
(405)826-5104
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html