Creating a shortcut


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating a shortcut
# 1  
Old 06-28-2012
Creating a shortcut

Hi, I want to match a column of one file with many others and take the average of each one and put them into one file (I know sounds complicated).

so the 1st file is just a list of names that I want to match with the 2nd file that have names along with rows of values.

Code:
awk 'NR==FNR{a[$1];next}($1 in a){print}' 1st.txt 2nd.txt

However I also want to match the 1st file with file 3,4,5,6 etc. How can I write a code (or modify it to do that). Basically 1st file matching with 2md, 3rd, 4th etc...

After I get the match in a output file for files 2,3,4,5 etc., I want to then average it using this code

Code:
awk '{ M=NF; for(N=4; N<=NF; N++) T[N]+=$N } END {printf("%f", T[4]/NR);for(N=5; N<=M; N++) printf("\t%f", T[N]/NR);printf("\n");}'

Again I want to do it simultaneously for all files at once. After I want all the values along with the name of the initial files (2,3,4,5 etc) into one final output file along with the values.

Hope I did not confuse anyone..

I am currently dong this one by one and it is taking forever... I just want one file i the end with everything (along with names for each row).

Thanks
# 2  
Old 06-28-2012
I think you could just specify more files after 2nd.txt
Code:
awk 'NR==FNR{a[$1];next}($1 in a){print}' 1st.txt 2nd.txt 3rd.txt 4th.txt

If the filenames allow you could use wildcards, e.g:
Code:
awk 'NR==FNR{a[$1];next}($1 in a){print}' match_file.txt file*.txt

# 3  
Old 06-28-2012
Hi thanks for replying. Yes that definitely works and I am slowly getting to the final stage.

Here is the new code that I have. Yet again there are still problems but I think a minor tweek from you experts can solve it.

Code:
awk 'NR==FNR{a[$1];next}($1 in a){print}' 1st.txt *filmatch.txt | awk '{ M=NF; for(N=4; N<=NF; N++) T[N]+=$N } END {printf("%f", T[4]/NR);for(N=5; N<=M; N++) printf("\t%f", T[N]/NR);printf("\n");}' > output.txt

What the above currently does is match all files based on 1st.txt and puts them into ONE output file. *filmatch.txt is made up of numerous files (2.txt, 3.txt, 4.txt etc.) and I want to include their name in the final file.

right now the current output looks like this (basically just the values that I want averaged):

Code:
0.068808	0.067252	0.068956	0.068141	0.068563	0.069272	0.070322	0.070029	0.069015	0.071708	0.071292	0.069931	0.071829	0.070628	0.069996	0.071036	0.070910	0.071590

But I want it to look like this:

Code:
1st.txt 0.068808	0.067252	0.068956	0.068141	0.068563	0.069272	0.070322	0.070029	0.069015	0.071708	0.071292	0.069931	0.071829	0.070628	0.069996	0.071036	0.070910	0.071590

2nd.txt 0.068808	0.067252	0.068956	0.068141	0.068563	0.069272	0.070322	0.070029	0.069015	0.071708	0.071292	0.069931	0.071829	0.070628	0.069996	0.071036	0.070910	0.071590

etc...

If you can get this to work then it would be great.

Thanks
# 4  
Old 06-28-2012
You could try something like this, which would print the filenames
Code:
awk 'NR==FNR{a[$1];next}($1 in a){print FILENAME $0}' 1st.txt *filmatch.txt

and take it from there...
# 5  
Old 06-28-2012
Hi, thanks. That partly worked (1st step). The first column becomes fused to the filename with that code.

Now I need to average the rows that have the same filename.

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

How to create a shortcut for Openoffice?

Hello all, I am facing some problem after installing the Openoffice in Solaris 10. The installation is successful but i cannot find any icon or shortcut on both Application and Desktop... please help me on this.... (8 Replies)
Discussion started by: aungyepaing
8 Replies

2. UNIX for Dummies Questions & Answers

Shortcut keys are not working

Hi all, I use the shortcut keys CTRL-a and CTRL-e to move cursor to start and end of line in shell prompt alot. But recently what happened to my system i don't know only CTRL-a is working not CTRL-e . If i press CTRL-e any other window in that desktop pop's up. Can any1 tell me how to correct... (2 Replies)
Discussion started by: vio719
2 Replies

3. Shell Programming and Scripting

Creating a Shortcut (to just type "l" but it runs "ls -lah")

How do I create shortcuts? For example: I just want to type one key "l" and have it output the command of "ls -lah" I believe it's creating a file called l with 755 permissions but I'm not sure where to put the file. *if it matters, I'm on a shared hosting web server using cPanel with... (2 Replies)
Discussion started by: ijustsawmars
2 Replies

4. UNIX for Dummies Questions & Answers

Comparison operators: shortcut name

There are a number of comparison operators used in scripting and programming languages, such as the following: =, ==, ===, !=, =~, <, >, <=, >=, etc Is there a shortcut name for them, such as one has for as being any capital letter? If not, it would mean that I would have to list them all for a... (2 Replies)
Discussion started by: figaro
2 Replies

5. Shell Programming and Scripting

Is there a shortcut in awk?

Is there a key board shortcut in vi editor to allow me to find the next ( or { that are corresponding to the first one? Thanks! It's % sign. (1 Reply)
Discussion started by: whatisthis
1 Replies

6. UNIX for Dummies Questions & Answers

Shortcut thing?

Hey, im new to Linux...totally new. I know there is a way to assign a type of variable or something to a directory, so instead of having to type "cd /var/www" etc, I could just assign a variable to the directory, so I could just do "cd $assignedvar" and it would be there...if you get what I... (0 Replies)
Discussion started by: mo0ness
0 Replies

7. UNIX for Dummies Questions & Answers

Shortcut

Dear Friends How i make shortcut in Tru64 unix for example make a shortcut for mail , i want to make a shortcut under / root the bath for mail # cd /var/spool/mail Regards, (1 Reply)
Discussion started by: fmmq
1 Replies

8. UNIX for Dummies Questions & Answers

Shortcut to home directory?

Also, Wherever you are exploring files in the UNIX structure you can jusy type "cd". This will take you to your home directory. Hope that helps. Cheers! (4 Replies)
Discussion started by: guest100
4 Replies

9. UNIX for Dummies Questions & Answers

shortcut in unix?

Sorry, anybody here knows how to make a shortcut in unix? Thanks. Sebastian. (4 Replies)
Discussion started by: seba
4 Replies

10. UNIX for Dummies Questions & Answers

Creating a Shortcut in a User Driectory

Can someone tell me how to create a shortcut within a users home directory to point to another location? P.S- And is shortcut the correct terminology? Thank you! (4 Replies)
Discussion started by: bachagalou
4 Replies
Login or Register to Ask a Question