Universal input -> name_n and name_n+1


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Universal input -> name_n and name_n+1
# 1  
Old 03-19-2012
Universal input -> name_n and name_n+1

Hi guys,
I'm working on 5000 files and trying to write a script that would take care of all of them. This is part of the script:
Code:
join name0000.pdb.OW.msd name0001.pdb.OW.msd > name0000+0001

I was trying to do something like this [without any effect]
Code:
for i in snap*.pdb.OW.msd; do 	
j=$((i+1))
join $i $j > $i_$j
done

where the input and output files would be automated for numbers from 0000 to 5000 or more - so the script would join files with n and n+1 in the names.
Any suggestions on how to do this or what kind of command should I use?
input1
HTML Code:
25464 136,871
25536 197,254
25569 130,513
25581 217,192
input2
HTML Code:
25464 134,463
25536 197,459
25569 133,560
25581 216,014
output
HTML Code:
25464 136,871 134,463
25536 197,254 197,459
25569 130,513 133,560
25581 217,192 216,014
25734 168,676 144,389
I have one more question - I'm using this script to count an average but it counts it after every line. How should I change, so that it would only overwrite one line with the ultimate average?
Code:
awk '{s+=$1}{print "Average for "FILENAME "=", s/NR}' name0000+00001>OUT

input
Code:
5,79846
0,042025
9,28421
1,38768

output
HTML Code:
Average for msd_name0000+00001= 5,79846
Average for name0000+00001= 2,92024
Average for name0000+00001= 5,04156
Average for name0000+00001= 4,12809
wished output
HTML Code:
Average for name0000+00001= 4,12809
Thanks for your time,
grincz
# 2  
Old 03-19-2012
If your system really does support enough arguments:

Code:
# Set $1, $2, ... to the list of files you want.
set -- snap[0-9][0-9][0-9][0-9].pdb.OW.msd

# Loop while there's more than 1 file in the list.
while [ "$#" -gt 1 ]
do
        join "$1" "$2" > "$1"_"$2"
        # Ditch $1, set $1=$2, $2=$3, ...
        shift
done

As for your average, to do it at the end, use END:

Code:
awk '{s+=$1} END {print "Average for "FILENAME "=", s/NR}' name0000+00001>OUT

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 03-20-2012
First part works like a charm, thanks!
I have a little problem with the second part- I didn't explane it well enough - sorry!

The OUT file should be storage file for all calculated averages, and it would be nice if I could use script like this:

Code:
awk '{s+=$1} END {print "Average for "FILENAME "=", s/NR}' calc_"$1"_"$2">OUT

and at the end the file would look like this:

Quote:
Average for calc_snap0000.pdb.OW.msd_snap0001.pdb.OW.msd= 0,276676
Average for calc_snap0001.pdb.OW.msd_snap0002.pdb.OW.msd= 0,776676
Average for calc_snap0002.pdb.OW.msd_snap0003.pdb.OW.msd= 0,576676
Average for calc_snap0003.pdb.OW.msd_snap0004.pdb.OW.msd= 5,276676
Average for calc_snap0004.pdb.OW.msd_snap0005.pdb.OW.msd= 3,276676
Average for calc_snap0005.pdb.OW.msd_snap0006.pdb.OW.msd= 0,376676
Take care,
grincz
# 4  
Old 03-20-2012
Use >>OUT instead of >OUT.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 03-20-2012
Thanks!


It looks like the 0002 file has every line unique...

Quote:
One more thing... After running the script I noticed that unfortunately the join command doesn't work properly - joint files 0001_0002 and 0002_0003 are empty, probably the 0002 file causes problems.
Quote:
Average for calc_name0000.pdb.OW.msd_name0001.pdb.OW.msd= 58,8237
Average for calc_name0001.pdb.OW.msd_name0002.pdb.OW.msd=
Average for calc_name0002.pdb.OW.msd_name0003.pdb.OW.msd=
Average for calc_name0003.pdb.OW.msd_name0004.pdb.OW.msd= 67,8626
Average for calc_name0004.pdb.OW.msd_name0005.pdb.OW.msd= 63,5823
Here are examples of files that are going into the join command:

name0000.pdb.OW.msd
Quote:
25581 208,533
25629 160,179
25653 150,588
25686 155,306
25713 139,765
name0001.pdb.OW.msd
Quote:
25581 160,931
25629 139,000
25653 215,945
25686 196,185
25713 172,236
name0002.pdb.OW.msd
Quote:
25581 132,004
25629 204,392
25653 220,155
25686 181,452
25713 144,370
name0003.pdb.OW.msd
Quote:
25581 144,509
25629 175,989
25653 208,533
25686 160,179
25713 150,588
Thanks!
Take care!

Last edited by grincz; 03-20-2012 at 05:40 PM.. Reason: update
# 6  
Old 03-21-2012
I'm sorry, I don't quite understand. Have you solved it or is there another question?
# 7  
Old 03-22-2012
It's solved, thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Security issues with universal access of file

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: If you look at the permissions associated with a symbolic link, it has universal access. Does this lead to... (0 Replies)
Discussion started by: linux17
0 Replies

2. Shell Programming and Scripting

universal bash + ksh command

I recently posted this and the answer I received was helpful, but here's my dilemma now: I have a script that makes a call like this in ksh initially, but it also doesn an ssh to another machine to do the same. the default shell is bash on there. Is there a command universal to ksh and bash... (1 Reply)
Discussion started by: mrwatkin
1 Replies

3. UNIX for Advanced & Expert Users

Universal portable disk for unix

Hi, I'm looking for one portable disk for unix to take, for example, data on solaris file system and put it on hp file system. Any idea where can I find this? Thanks a lot, Sergio (3 Replies)
Discussion started by: sergiobonfim
3 Replies

4. Ubuntu

Universal Repositories for All Linux Distros

Is it possible to use Other Distro's ( i.e Debian's or Ubuntu's ) repositories in Fedora? If not then what should be done to make common repositories for all linux distros. regards, Arun Maurya (2 Replies)
Discussion started by: arun_maurya
2 Replies
Login or Register to Ask a Question