Hi,

I have a problem with a script which I am writing for my final thesis. The thesis must be ready within two weeks, so I would really appreciate if you could help me. My thesis is about h-node.

The script will deal with two different logs of user actions to figure out what kind of hardware contributions I have made to h-node. Specifically, I am trying to count how many contributions I have made per each hardware class.

I have two source files for the script. Both contain lines of data which I am trying to process. Here are some examples of the content:

Source file 1:
Format: the model DEVICE_NAME has been [updated|inserted] by USER_NAME at DATE_AND_TIME


the model E220 HSDPA Modem / E270 HSDPA/HSUPA Modem has been updated by lammi87 at 22:48, 18 May 2012


Source file 2:
Format: HARDWARE_CLASS DEVICE_NAME


notebook ProBook 6555b


Source file 1 contains most of the stuff I need. The only thing it does not have is the HARDWARE_CLASS associated with each line, so I have to get it from the source file 2.

Source file 1 has a line per each contribution I have made but the source file 2 does not. Even when I make multiple contributions to one device, only one line containing that DEVICE_NAME is found in the source file 2.

So, I need to count how many times a DEVICE_NAME found in source 2 appears on source 1 per each HARDWARE_CLASS.

The problem is this:

I don't seem to get the array in my script to work correctly. I am trying to save all the DEVICE_NAMES (which can contain white spaces and special characters like ', (, ), [ and ] and extra tabs and white spaces at the end of each line) to the array as one DEVICE_NAME per each slot in the array by running a for loop.

Then I will run another for loop within the other one to count how many times a line containing a particular DEVICE_NAME is present in source 1. The problem is that no matter what I try, I can't get the array to work.

Sorry for long explanation. Example source files and the script can be found as attachments below.

#!/bin/bash

# This is the part of my script which has been causing problems for me.
# I know it does not work at all, but it gives you a picture of what I 
# am trying to do.
 
# $1 = source file 1
# $2 = source file 2
# $3 = output file

TABLE_FORMAT="%-35s%8s\n"
IFS="
"

for CLASS in notebook videocard soundcard wifi ethernet-card \
sd-card-reader webcam bluetooth acquisition-card 3G-card \
host-controller fingerprint-reader RAID-adapter modem printer \
scanner
do

   DEVICE_NAMES=$( cat $2 | grep $CLASS | sed -e "s/^$CLASS //" )
   # sed -e /\'/d -e /\(/d -e /\)/d -e /\[/d -e /\]/d

   for NAME in "${DEVICE_NAMES[*]}"
   do

      NUM=$( cat $1 | grep $NAME | wc -l)
      let "TOTAL=$TOTAL+$NUM"

   done

   printf $TABLE_FORMAT $CLASS $NUM >> $3
   NUM=0

done

printf $TABLE_FORMAT "Total" $TOTAL >> $3
the model Atheros Communications Inc. AR5413/AR5414 Wireless Network Adapter 
[AR5006X(S) 802.11abg] (rev 01) has been inserted by lammi87 at 19:31, 22 March 
2013
the model Advanced Micro Devices [AMD] nee ATI Cedar PRO [Radeon HD 5450] has 
been inserted by lammi87 at 14:29, 6 March 2013
the model G1S-AK005G has been inserted by lammi87 at 12:54, 18 January 2013
the model NVIDIA Corporation G84 [GeForce 8600M GT] (rev a1) has been inserted 
by lammi87 at 12:48, 18 January 2013
the model ProBook 6555b has been updated by lammi87 at 11:08, 18 January 2013
wifi Atheros Communications Inc. AR5413/AR5414 Wireless Network Adapter 
[AR5006X(S) 802.11abg] (rev 01) 
videocard Advanced Micro Devices [AMD] nee ATI Cedar PRO [Radeon HD 5450]       
notebook G1S-AK005G     
videocard NVIDIA Corporation G84 [GeForce 8600M GT] (rev a1)    
notebook ProBook 6555b  

Reply via email to