LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxQuestions.org Member Success Stories
User Name
Password
LinuxQuestions.org Member Success Stories Just spent four hours configuring your favorite program? Just figured out a Linux problem that has been stumping you for months?
Post your Linux Success Stories here.

Notices

Reply
 
Search this Thread
Old 08-02-2012, 09:09 AM   #1
kabester
LQ Newbie
 
Registered: Aug 2012
Distribution: ubuntu
Posts: 1

Rep: Reputation: Disabled
Smile 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!!!!

Last edited by kabester; 08-02-2012 at 09:10 AM.
 
Old 08-02-2012, 03:20 PM   #2
ivanvodisek
LQ Newbie
 
Registered: Aug 2012
Location: croatia
Distribution: xubuntu
Posts: 22

Rep: Reputation: 0
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Looping in Many Files with Shell Programming ali2011 Programming 5 07-27-2012 01:30 PM
[SOLVED] bash looping through a group of files alternatives to ls? patolfo Linux - Software 4 03-10-2012 07:19 AM
[SOLVED] looping thru input files with different number of days. btacuso Programming 8 11-03-2010 11:54 PM
Search tools (Affinity, Tracker Search Tool, etc.) not working - don't find any files Adamantus Linux - Newbie 1 03-29-2009 11:21 PM
looping trough files BackwardsDown Programming 4 02-09-2007 10:39 PM


All times are GMT -5. The time now is 11:55 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration