Results 1 to 3 of 3
trying to do something very basic but having a very difficult time.
assuming the following:
Code:
date | awk '{print "'\''"$2,$3"'\''"}'
will return
'Oct 07'
and
Code:
ls -ltr | ...
- 10-08-2008 #1Just Joined!
- Join Date
- Oct 2008
- Posts
- 1
1 Line script syntax problem
trying to do something very basic but having a very difficult time.
assuming the following:
will returnCode:date | awk '{print "'\''"$2,$3"'\''"}'
'Oct 07'
and
will returnCode:ls -ltr | grep `echo com`
-rw------- 1 ??????? ????? 2440 Jul 06 19:15 commands.txt
Why is it that I cannot combine them both to list and grep by 'Oct 07'?
returnsCode:ls -ltr | grep `date | awk '{print "'\''"$2,$3"'\''"}'`
grep: 0652-033 Cannot open 7'.
I just realized even if I did get this script's syntax correct it would not work as date returns Oct 7 and when doing ls -ltr the date is displayed as Oct 07
- 10-08-2008 #2
This is because the "date | awk ..." command returns two words -- Oct 07, so grep tries to grep the file "7" for the word "Oct". Perhaps if you put the date command in double-quotes
I have no idea if that'll work, but you could give it a try....Code:ls -ltr | grep "`date | awk '{print "'\''"$2,$3"'\''"}'`"
Welcome to the forums
Registered Linux user #388328 || Registered LFS user #15880
AMD 64 X2 4600+ :: 2X1GB DDR2 800 :: GeForce 9400 GT 512MB :: ASUS M2N32 Deluxe :: 4X250GB SATAII
Need instant help? Try us on IRC -- #linuxforums on freenode
- 10-08-2008 #3Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
If you are trying to list files/folders modified within less than 24 hours started from 00:00 today, try to use command find instead:
find . -daystart -ctime -1 -exec ls -l {} \;
Or if you still want to use ls and grep, try
ls -ltr | grep "`date '+%b %d'`"


Reply With Quote