hi all
I am new to awk/perl I would appreciate it if you could help!
how do I read a sub folder and their files.
e.g. simulation/10ms/router1.dat, router2.dat,..., router16.dat
simulation/100ms/router1.dat, router2.dat,..., router16.dat
simulation/300ms/router1.dat, router2.dat,..., router16.dat
1. I need to read and plot the number columns form each file and sub folder:
simulation/10ms/router2.dat, ..., simulation/1500ms/router2.dat
2. how do I calculate and plot the interpolation line from two files
router2.dat using awk/perl
10 43.4
20 56.8
30 87.9
:
100 23.8
Normally, one doesn't use awk or perl to read files in subfolders -- that's usually taken care of by the command line. In perl, it's possible to use the File::Find module (do a man on File::Find). But I find that module confusing and unwieldy, especially when you just want to read all the files in a directory. Better use a find pipeline into a "while read file; do perl .... $file; done" loop, or use xargs to similar effect.
Concerning question #1, do you need to plot the columns from each file separately, or do you need to aggregate them in some way? That is, all from one folder, all together, etc. If it's the latter, it might make more sense to import that data into a, for instance, MySQL database. Otherwise, you'll need to specify the command line with every single file in each group. (Or use the File::Find module with perl).
Concerning 2. You don't "plot" anything with perl/awk. You do that with another tool, such as gplot. If you want to use file2 (sender.dat) together with file1 (router2.dat), you can simply merge them together with sort:
The output should go to a temporary file or be piped into awk/perl, which can then do the interprolation. Unfortunately, I cannot interpret your formula for y. Especially the y[i+1] bit. With awk and perl, you can look *behind* a line, but ahead of one. So it would be better if you re-do the formula in terms of i and i-1.
Unfortunately, I cannot interpret your formula for y. Especially the y[i+1] bit. With awk and perl, you can look *behind* a line, but ahead of one. So it would be better if you re-do the formula in terms of i and i-1.[/quote]
here is the interpolation equation.
the slope is give by: {y(i+1) - y(i)} / {t(i+1) - t(i)}
Terribly sorry, but I don't get it. I don't know what you mean by y(i) or t(i). Maybe you can give an example. Again, we'll have to change this formula to i and i-1 instead of i+1 and i.
sorry for that..
assume that we have sampled value in different time:
file1: router1.dat
t load
60 10.26
120 11.52
180 11.52
240 12.00
where t(1)=60, y(1)=10.26, t(2)=120, y(2)=11.52, etc.
file2: sender1.dat
t estimated value
100 18.18
200 8.33
300 9.21
400 6.99
where t(1)=100, y(1)=18.18, t(2)=200, y(2)=8.33, etc.
in this case, i need to calculate the interpolation value, which is
y = y(i) + {(y(i+1) - y(i)) (t - t(i))} / {t(i+1) - t(i)}
as shown below
y = 10.26 + ({(11.52 - 10.69)}30)/60...
I hope, it doesn't give you any misunderstanding this time. I know, I should make it put an example at the first time...
Quote:
Originally Posted by otheus
Terribly sorry, but I don't get it. I don't know what you mean by y(i) or t(i). Maybe you can give an example. Again, we'll have to change this formula to i and i-1 instead of i+1 and i.
Hello. I'm trying to convert an awk script I wrote to perl (which I just started self-teaching). I tried the a2p command but I couldn't make sense of most of it.
Here was the awk code:
BEGIN{
FS = ","
print "NAME\tLOW\tHIGH\tAVERAGE"
a=0
}
{
if(a==0){
a+=1 (1 Reply)
Hello,
I searched online; it seems that perl use $NR as NR in awk; however it does not work for me. For example, how to re-write the following awk using perl:
awk '{ print NR}' inputfile---------- Post updated at 01:55 PM ---------- Previous update was at 12:49 PM ----------
I found... (2 Replies)
Hello folks.
After awk, i have decided to start to learn perl, and i need some help.
I have following output :
1 a
1 b
2 k
2 f
3 s
3 p
Now with awk i get desired output by issuing :
awk ' { a = a FS $2 } END { for ( i in a) print i,a }' input
1 a b
2 k f
3 s p
Can... (1 Reply)
Hi Everyone,
cat 1.txt
a <abc
b vfff
c 000>
d 4444
the output is:
<abcvfff000>
by using perl or awk, can get the value betwee "<abc" and ">", assume 1.txt has lots of those tags, so the output can filter out all those values.
Please advice.
Thanks (4 Replies)
DEAR ALL,
i am using following command to fetch some records from more then 50000 files... command is taking more time ....
can i have perl command for the same...( i am New to perl )
awk -F "|" '{ if($4==3244898 && $5==5000185) print $66}' *.DATA (2 Replies)
awk -F "|" '{print $2$3$4 upto $30}' file1 > file2
Same logic, i want to write it in perl
I tried
#!/bin/usr/perl
my $line;
open FH, "<file1" or die " Can't open file $!";
open FH1, ">file2" or die "Can't open file ";
while (<FH1>){
$line = (split /\|/,$_);
print FH2 $line;... (3 Replies)
I have a script to get server information i wrote in perl because i would like to learn it (and I use it for work). It works great, however i would like to know if there is a good way to reduce the following line.
Sean (6 Replies)
Hi All,
My Input file looks like below:
Input:
100,200,300
$fw=`head -1 test.csv | awk -F, '{print \$1}'`;
$fw="'$fw"
$fw="$fw'"
print $fw
Output:'100'
I want the first field to be printed in single quotes ('') like above.
I could get the ouptput but the problem is single... (6 Replies)
Dear Collegue
Do anybody help me to convert this AWK script to Perl script
{
for (i = 2; i <= length ($0); i++) {
x = substr($0, i , 1)
if (c > 0) {
b = b x
if (x == "(") c++
... (2 Replies)
Hello Guys,
I am refering to this great forum once again for help.
After various attempts at this, I am still failing to obtain the desire effect.
I have to write a perl script which:
1- reads two values from the user (e.g name & passwd)
2- check each value against a file containing the... (7 Replies)