LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   LinuxQuestions.org Member Success Stories (http://www.linuxquestions.org/questions/linuxquestions-org-member-success-stories-23/)
-   -   looping through files to search for given substrings (http://www.linuxquestions.org/questions/linuxquestions-org-member-success-stories-23/looping-through-files-to-search-for-given-substrings-4175419976/)

kabester 08-02-2012 09:09 AM

looping through files to search for given substrings
 
#!/bin/bash

dir="/home/ubuntu/data"
# loop though all the required dates
for ldate in $(echo 2012{01,02,03,04,05,06,07,08,09,10,11,12}{01,11,21})
do
# for each date
# check if there is a file in input directory which contains the date
file=$(ls ${dir}/ | grep ${ldate})
if [[ -n ${file} ]]; then
# file was found
name=${file##*/}
fdate=${name:11:8}
size=$(stat -c %s ${dir}/${name})
echo "date=${ldate}, name=${name}, size=(${size} bytes)"
else
# file was not found
echo "date=${ldate}, no file matching"
fi
done












Bash is fun....................
just made this scripts,
it searches part of filenames for a date given, which is a substring for a file name,if the date macthes part of the file name it prints out else it print that date given as a substring does not macth.make your edits towards your scripts.bashhhhhhhhhhhhh!!!!

ivanvodisek 08-02-2012 03:20 PM

Look what I find on web. It is about making keyboard caps led flashing when hdd is in use. Didn't try it personally, but i'm amazed by the power of shell scripts.

Code:

#!/bin/bash

# Check interval seconds
CHECKINTERVAL=0.1

# console
CONSOLE=/dev/console

#indicator to use [caps, num, scroll]
INDICATOR=caps

getVmstat() {
  cat /proc/vmstat|egrep "pgpgin|pgpgout" 
}
#turn led on
function led_on()
{
    setleds -L +${INDICATOR} < ${CONSOLE}
}
#turn led off
function led_off()
{
    setleds -L -${INDICATOR} < ${CONSOLE}
}
# initialise variables
NEW=$(getVmstat)
OLD=$(getVmstat)
##
while [ 1 ] ; do
  sleep $CHECKINTERVAL # slowdown a bit
  # get status
  NEW=$(getVmstat)
  #compare state
  if [ "$NEW" = "$OLD" ]; then 
    led_off ## no change, led off
  else
    led_on  ## change, led on
  fi
  OLD=$NEW 
done



All times are GMT -5. The time now is 05:01 AM.