Tuesday, March 16, 2010

How to get the latest file from the directory

#
way 1:
$ ls -lrt | awk '{ f=$NF }; END{ print f }'
#
#The above awk is to print the last argument of the last line

#
way 2:
$ ls -t1 | head -n

REFERENCE: bash - parameter expansion, i.e. http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_02

file=data.txt
  echo ${file%.*}
  echo ${file#*.}

outputs the file base and extension respectively ("data" and "txt").

${variable#pattern} is similar to "echo $variable |sed 's/^pattern//'"
but the pattern matching isn't "greedy" unless you double the #.
Likewise ${variable%pattern} is similar to
"echo $variable | sed 's/pattern$//'"

Thursday, March 4, 2010

Read file writting strings into array

declare -a ARRAY
count=0

while read line; do
echo $line
ARRAY[$count]=$line
let count=count+1
echo $count
done < ips.tmp

echo ${ARRAY[1]}
echo ${#ARRAY[@]}

Wednesday, March 3, 2010

File System workload generator

In addition to the previous post:

FileBench looks like a perfect tool for the load generation.