List the files with string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting List the files with string
# 1  
Old 11-13-2009
List the files with string

I want to list all the files which are having today's date in its header...

Please let me know if this can be achveived by a single command
# 2  
Old 11-13-2009
Code:
grep $(date) *

# 3  
Old 11-13-2009
Code:
printf "'%s'" $(date "+%m/%m/%Y") | read dt && grep -l $dt /directory/to/search/*

# 4  
Old 11-14-2009
MySQL

Hi Steady and Jim,

I want to search Today's date only in the file header .. I dont want to search through the file content.

The search will be performed on the all files in the directory and to get the filenames which is having the Today's date on its header,

Please let me know if I am not clear.

Please help me if this can be achieved in a command.

Thank you,
# 5  
Old 11-14-2009
then you should provide your sample input file
# 6  
Old 11-14-2009
MySQL my workbook code

Hi,
My sample file will be like

H|ABC|DEF|20091112
D|abc|adsf|asdf|asdf
D|abc|adsf|asdf|asdf
D|abc|adsf|asdf|asdf
D|abc|adsf|asdf|asdf
T||abc|adsf|asdf|asdf

I am novice to shell scripting. but i tried to prepare a script like below.

Code:
EtlDate='20091112';
INBOUNDDIR='/cba_app/BANKWEST/BW117/DEV/inbound'
for fname in $INBOUNDDIR/abcb_akf840*.csv; do
head -1 $fname | grep $EtlDate > NULL
if(( $? == 0 )); then
    echo $fname
  fi

done


I want a command to list out the filenames with the date in the file header...
# 7  
Old 11-14-2009
gawk
Code:
$ EtlDate='20091112'
$ awk -v d="$EtlDate"  -F"|" 'FNR==1&& $NF==d{print "found "d" in "FILENAME;nextfile}' file*

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding a string in a list of files, print file names

I'm interested in writing a report script using BASH that searches all of the files in a particular directory for a keyword and printing a list of files containing this string... In fact this reporting script would have searches for multiple keywords, so I'm interested in making multiple... (2 Replies)
Discussion started by: chemscripter904
2 Replies

2. Shell Programming and Scripting

Grep string in files and list file names that contain the string

Hi, I have a list of zipped files. I want to grep for a string in all files and get a list of file names that contain the string. But without unzipping them before that, more like using something like gzcat. My OS is: SunOS test 5.10 Generic_142900-13 sun4u sparc SUNW,SPARC-Enterprise (8 Replies)
Discussion started by: apenkov
8 Replies

3. Shell Programming and Scripting

How to list the files having particular string in it ?

I want to list the name of files with path having perticular string in it. search must be start from root (/) dir. Thanks:) (3 Replies)
Discussion started by: anandgodse
3 Replies

4. Shell Programming and Scripting

grep exact string from files and write to filename when string present in file

I am attempting to grep an exact string from a series of files within a directory and append that output to the filename when it is present in the file. I've been after this all day with no luck. Thanks for your help in advance :wall:. (4 Replies)
Discussion started by: JC_1
4 Replies

5. UNIX for Dummies Questions & Answers

Creating a column based list from a string list

I have a string containing fields separated by space Example set sr="Fred Ted Joe Peter Paul Jean Chris Tim Tex" and want to display it in a column format, for example to a maximum of a window of 100 characters And hopefully display some thing like Fred Ted Joe ... (3 Replies)
Discussion started by: kristinu
3 Replies

6. Solaris

Replacing a string in a long list of files

I have a script that needs to read a file with a long list of /path/filenames - replace the name of the server in each file - and write the file to the same path with a date extension. This is the script that I have so far #!/bin/ksh umask 022 LIST=`scripts.list` for i in $LIST do ... (2 Replies)
Discussion started by: bjdamon
2 Replies

7. Shell Programming and Scripting

Help to find string and return following characters from list of files

Hi, I'm fairly new to UNIX, but hopefully some-one can help me with this: I am using the following code to find files with the name "example.xml": find . -name "example.xml" -print that would print me a list like the example here: ./dir1/dir2/example.xml... (5 Replies)
Discussion started by: boijie
5 Replies

8. UNIX for Dummies Questions & Answers

counting a list of string in a list of txt files

Hi there! I have 150 txt files named chunk1, chunk2, ........., chunk150. I have a second file called string.txt with more than 1000 unique strings, house, dog, cat ... I want to know which command I should use to count how many times each string appears in the 150 files. I have tried... (4 Replies)
Discussion started by: Pep Puigvert
4 Replies

9. UNIX for Dummies Questions & Answers

How to List and copy the files containing a string

:confused: I have more than 8000 files in a dir, I need to copy to other dir which containing the "sample" I tried grep -il "1189609240791-1268115603299237276@216.109.111.119 ' | cp /tmp/inv Nothing is happening for long time for 100 file dir too, Any one can help me? (11 Replies)
Discussion started by: redlotus72
11 Replies

10. UNIX for Dummies Questions & Answers

Search a string from list of input files

Hello, I am trying to match a string between line one and line two with in the file. But I dont want to search based on the given filename. Instead I want to search for all available files in the specific directory. Please help me on the above. (2 Replies)
Discussion started by: sivakumarvenkat
2 Replies
Login or Register to Ask a Question