ls -l on a directory and grep for a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ls -l on a directory and grep for a variable
# 1  
Old 08-12-2010
ls -l on a directory and grep for a variable

I want to find all entries in a directory for a given date, and write those entries to a file.
Code:
#!/bin/ksh
d=`date '+ %b %e'`   # -- this works e.g. Aug 1
files=`/usr/bin/ls -l|grep '$d' ` # -- the pipe doesnt work, but the ls -l does.

What do i need to do to be able to send the list of files to '> an_output.dat'

Last edited by vbe; 08-12-2010 at 11:07 AM.. Reason: code tags
# 2  
Old 08-12-2010
the shell will not substitute $d when masked with '', use ""
This User Gave Thanks to funksen For This Post:
# 3  
Old 08-12-2010
:-)
Thanks! I also added the echo "$files" to capture the output in a flat file. Very much appreciate it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to grep all the files inside the directory and Sub directory

Hi, I have used the command cat * | grep -r <<String>> * It returns: cat : JAN : is directory *********************** ********************* My directory structure: log - JAN -catalina.out -FEB -catalina.out -MARCH ... (11 Replies)
Discussion started by: nanthagopal
11 Replies

2. Shell Programming and Scripting

grep using variable

I have a pattern like: column "5" is missing PS: the no is in double quotes. The number usally changes, so we use a loop to grep. grep 'column "$number" is missing' filename.txt But it is not working.... How to solve this? (2 Replies)
Discussion started by: karumudi7
2 Replies

3. Shell Programming and Scripting

Grep through a variable

I want to search a text in file but that file is pointing to variable. ex: file=there was nothing special grep "there was nothing" $file but its not working . Can u let me know that how we can use variable($file) in grep command. Please use code tags (6 Replies)
Discussion started by: allthanksquery
6 Replies

4. Shell Programming and Scripting

grep using variable

how can I use grep with a variable to find a value? cat data.out Hello World grep "Hello World" data.out Hello World ## Value found I want to do something like this but can't seem to get it to work any suggestions would be appreciated. var="Hello World" grep $var data.out (3 Replies)
Discussion started by: BeefStu
3 Replies

5. Solaris

grep recursively in a directory

Hi, how to grep recursively in a directory on Solaris OS. grep -r throws an error that -r is an invalid option. Please tell me if you have any solution. Regards, Jeevan. ps. I searched this forum for solution, but could not find anything useful. (4 Replies)
Discussion started by: jredx
4 Replies

6. Shell Programming and Scripting

grep all files in a directory

I am not sure if i am doing this correctly since it returns quickly. i need to grep for a keyword in all files in a directory grep keyword /mydirectory is that correct? I just want to know which files have a keyword in it. i am using korn shell in solaris 5.1. There does not appear to... (12 Replies)
Discussion started by: guessingo
12 Replies

7. Shell Programming and Scripting

directory as variable

I have the code below, which works fine when I have directories like dir1 and ../dir but does not work with ~/dir. Can anyone help? echo enter a directory read dir echo $dir if then echo it is a dir else echo not dir fi (3 Replies)
Discussion started by: desperatelySeek
3 Replies

8. Shell Programming and Scripting

grep a variable

Hi all, I am trying to do a simple thing in my mind. However I am fairly new to bash. What I need to do is create a folder for each partition on each CD, and each partition has a unique name (with spaces in it, do not ask why, it is already done :confused: ) . All CD's will show up... (2 Replies)
Discussion started by: sgstuart
2 Replies

9. Shell Programming and Scripting

Sed variable substitution when variable constructed of a directory path

Hello, i have another sed question.. I'm trying to do variable substition with sed and i'm running into a problem. my var1 is a string constructed like this: filename1 filerev1 filepath1 my var2 is another string constructed like this: filename2 filerev2 filepath2 when i do... (2 Replies)
Discussion started by: alrinno
2 Replies

10. Shell Programming and Scripting

How to grep a variable?

Hi, I'd like to grep a variable that I saved in the program. Like grep '0\$variable1' file1 Does someone know what's wrong with this command? Thanks a lot! (2 Replies)
Discussion started by: whatisthis
2 Replies
Login or Register to Ask a Question