Hi,
I would like to get the following script to work. The script should search for file that are bigger then 200 and that have been created or modified today!
The problem is the comparator == does not work! when i compare the ( $6 == $dat ) i don't get any output. when i change the $dat to "2010-02-06", i get the following output.

khalid@ubuntuFS:~/uppgift7$ ./uppgift17.sh /home/khalid/uppgift7/
/home/khalid/uppgift7/
2010-02-17
271k 2010-02-06 uppgift11.sh 
 270k 2010-02-06 uppgift14.sh 
 221k 2010-02-06 uppgift16.sh 
 288k 2010-02-06 uppgift17.sh 
 296k 2010-02-06 uppgift17.sh.save 
 264k 2010-02-06 file2 
 1526k 2010-02-06 file3 

2010-02-17
khalid@ubuntuFS:~/uppgift7$

This is the script that i have a problem with.

#!/bin/bash

if [ -z $1 ]

then
echo "Enter a path: "
else [ -n $1 ]
path1=$1

echo $path1
dat=`date +%F`
echo $dat

file="$( ls $path1 -lR | awk '{if(( $5 > 200 ) && ( $6 == $dat ))print $5 "k\t" $6 "\t" $8 "\n\v\r"}')"
echo $file
fi

I know how to solve a problem with the command sed, i appreciate it if someone could tell me why the comparator is not working.

Thanks in advanced.

The problem is in how awk accepts an external variable, in this case $dat.

awk -v Var_date=$dat '{if(( $5 > 200 ) && ( $6 == Var_date ))

Just use the find command - this is bread and butter for find.

$ find work -daystart -mtime -1 -size +2000c -ls
327592    4 drwxr-xr-x   2 forum    forum        4096 Feb 17 16:18 work
327419   12 -rwxr-xr-x   1 forum    forum        9339 Feb 17 16:18 work/a.out
$ find work -daystart -mtime -1 -size -2000c -ls
327355    4 -rw-r--r--   1 forum    forum         439 Feb 17 16:18 work/foo.c~
313613    4 -rw-r--r--   1 forum    forum         443 Feb 17 16:18 work/foo.c

Thanks a lot Aia, That was the missing part! Appreciate is a lot.

Thanks a lot Salem. I will try the sed in the script to practice a bit :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.