awk using ssh variable?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk using ssh variable?
# 1  
Old 08-03-2008
awk using ssh variable?

I have a file named Atoms that has a list of atoms listed vertically, like:

O
C
Na

etc. There is a variable number of them.

I want to count their occurences in another file. I want to do this by saving each atom as a variable, preferabbly in an associative array, then counting how many there are in the other file. I already can count the number of atoms, and I save that into $numatoms

My problem right now is the awk command recognizing the variable $i from the for loop. The part where it says NR=="$i" doesn't seem to work. Also, afterward, I still wouldn't know how to count the occurences in another file, which is also based on a variable, titled $name.axyz. I'm fairly new, and help would be appreciated!!! Thanks.


for (( i=1; i < $numatoms; i++ )); do
count[$i]=$(awk {'NR=='"$i"'{ print "$1"}' Atoms)
echo $count[$i]
done
# 2  
Old 08-03-2008
Use only awk:
Code:
awk '{a[$0]++}END{for (i in a) printf "%s\t%s %s\n",i,a[i],"Atoms"}' file > new_file

# 3  
Old 08-04-2008
Java

Sorry, I'm really new to awk, could you explain your line a little? I tried it and it didn't work. What is meant by file and new_file for, is that where the searching is done? Thanks
# 4  
Old 08-04-2008
Code:
awk '{
a[$0]++                               #read each line($0) from source file in array a and count ++ occurrences of $0
}
END                                   #at the end of file do..
{
for (i in a)                          #for each member (i)of array a
printf "%s\t%s %s\n",i,a[i],"Atoms"   #format the output, read man printf for more options
}
' file > new_file                     #declare the source file and set the output (>) to new_file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How can I assign awk's variable to shell script's variable?

I have the following script, and I want to assign the output ($10 and $5) from awk to N and L: grdinfo data.grd | awk '{print $10,$5}'| read N L output from gridinfo data.grd is: data.grd 50 100 41 82 -2796 6944 0.016 0.016 3001 2461. where N and L is suppose to be 3001 and 100. I use... (8 Replies)
Discussion started by: geomarine
8 Replies

2. Shell Programming and Scripting

Passing a variable via ssh, can't quite get it right

Hi Guys n Girls, Below im using a while command to wait for a file on another server then carrying on with the script..... I dont believe the $Sausage1 variable is being passed to the other server so its not finding the file. If i replace the variable with the date then it works as expected. ... (2 Replies)
Discussion started by: twinion
2 Replies

3. Shell Programming and Scripting

how to assign value to the variable through ssh

Hi All, i am writing a shellscript to compare cksum of the file in local machine and after copying to remote machine. i am not able to assign command output value to variable in remote machine through SSH. PFB code for this. code: ###### Get File size of the file in local remote system ... (3 Replies)
Discussion started by: katamsivakumar
3 Replies

4. Shell Programming and Scripting

help about the ssh accpect a variable

# dir=/mnt # ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@10.0.2.3 'cd $dir;ls' The $dir doesn't take effect any help?? ( I want use variable to do something Thanks in advance (1 Reply)
Discussion started by: yanglei_fage
1 Replies

5. Shell Programming and Scripting

using awk for setting variable but change the output of this variable within awk

Hi all, Hope someone can help me out here. I have this BASH script (see below) My problem lies with the variable path. The output of the command find will give me several fields. The 9th field is the path. I want to captured that and the I want to filter this to a specific level. The... (6 Replies)
Discussion started by: Cowardly
6 Replies

6. Shell Programming and Scripting

use awk to ssh from variable in flat file

flat file looks like ooss-pfgg-1234,vol_name_1, mail-list decoded = hostname,volum_name,mail_list each line has diff info am trying to ssh into each fist field, check vol usage for second field, and if greater than 90% send mail to mail-list got the second and third part working, ... (1 Reply)
Discussion started by: riegersteve
1 Replies

7. Shell Programming and Scripting

Variable value in ssh

Hi, I'm creating a script where I connet to a remote machine, I execute a command (I get a pid of an application) and I kill the application. I wrote this: ssh $HOST_WHITEBOARD<<END COMMAND_GET_PID_WHITE="ps aux | grep something | awk '/Sl+/ {print \$2}' | awk 'begin {row=0} row==0... (4 Replies)
Discussion started by: abdujaparov
4 Replies

8. Shell Programming and Scripting

assign awk's variable to shell script's variable?

Dear All, we have a command output which looks like : Total 200 queues in 30000 Kbytes and we're going to get "200" and "30000" for further process. currently, i'm using : numA=echo $OUTPUT | awk '{print $2}' numB=echo $OUTPUT | awk '{print $5}' my question is : can I use just one... (4 Replies)
Discussion started by: tiger2000
4 Replies

9. Shell Programming and Scripting

setting a variable, using SSH and awk?

hi there I am trying to get a value from a remote machine into a local variable. To get this value i want to use awk but im having trouble getting it to run, am i escaping in the right places here and using the right quotes (i must have tried a million combinations :() # VAR=`ssh server1... (5 Replies)
Discussion started by: hcclnoodles
5 Replies

10. Shell Programming and Scripting

Issue in Variable in SSH

Friends, I want to write a script. The logic follows 1. Script starts 2. SSH to Remote Machine and check whether /home/testUser dir is there or not. 3. If it is there, am assigning a value to a variable. else not 4. If the variable is set, the do the copy from remote machine to my local... (2 Replies)
Discussion started by: balamv
2 Replies
Login or Register to Ask a Question