how to find files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to find files
# 1  
Old 03-26-2011
how to find files

1st file

1 4 7
c b 8
3 6 a

2nd file

z 6 1
q g w
3 t 5

suppose i have 1000 files with 3 fields.I don't know if there is value in 4th fields out of those 1000 files. I want to print those files where there is value in the 4th fields.

---------- Post updated at 12:41 PM ---------- Previous update was at 12:18 PM ----------

Can anyone help me with the requirement
# 2  
Old 03-26-2011
suppose that all your files are named by *.txt. And fields delimiter is space " ".
Code:
cd yourDir
grep -El ".*\s.*\s.*\s.*" *.txt

will list all the filenames with 4 columns.
# 3  
Old 03-26-2011
can you please explain how the script works
# 4  
Old 03-26-2011
go through all the files, lookin for if there is one line contains the 4th field. if found one, print only the file name.
# 5  
Old 03-26-2011
i am not able to understand what
-El ".*\s.*\s.*\s.*" means
# 6  
Old 03-26-2011
Code:
-E, --extended-regexp
              Interpret PATTERN as an extended regular expression (ERE, see below).  (-E is specified by POSIX.)

 -l, --files-with-matches
              Suppress  normal  output; instead print the name of each input file from which output would normally have been printed.
              The scanning will stop on the first match.  (-l is specified by POSIX.)
 ".*\s.*\s.*\s.*" is regular expression to find out the pattern with 4 fields. in your case.

if you read man page of grep command, you can get all those info.
# 7  
Old 03-26-2011
Another possible option, assuming you look for txt files:
Code:
files=$(find . -type f -name '*.txt' | awk -F"/" '{print $NF}')

for i in $files
do
awk 'NF>3{print "Files with more than 3 columns-->",FILENAME}' $i | uniq
done


Or a faster code than my first reply:

Code:
files=$(find . -type f -name '*.txt' | awk -F"/" '{print $NF}')

for i in $files
do
awk 'NF>3{print "File with at least one line with " NR " columns-->",FILENAME;exit 1}' $i 
done

Regards

Last edited by cgkmal; 03-27-2011 at 03:31 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find -ctime -1 cannot find files without extention

The problem is this one. I tar and gzip files on remote server find . -ctime -1 | tar -cvf transfer_dmz_start_daily.tar *${Today}*.*; Command find . -ctime -1 Doesn't find files without extension .csv .txt I have to collect all files for current day, when the program... (1 Reply)
Discussion started by: digioleg54
1 Replies

2. Shell Programming and Scripting

find -ctime -1 cannot find files without extention

The problem is this one. I tar and gzip files on remote server Code: find . -ctime -1 | tar -cvf transfer_dmz_start_daily.tar *${Today}*.*; Command Code: find . -ctime -1 Doesn't find files without extension Code: .csv .txt I have to collect all files for current... (1 Reply)
Discussion started by: digioleg54
1 Replies

3. Shell Programming and Scripting

Find command to find a word from list of files

I need to find a word '% Retail by State' in the folder /usr/sas/reports/RetailSalesTaxallocation. When I tried like below, -bash-4.1$ cd /usr/sas/reports/RetailSalesTaxallocation -bash-4.1$ find ./ -name % Retail by State find: paths must precede expression: Retail Usage: find ... (10 Replies)
Discussion started by: Ram Kumar_BE
10 Replies

4. UNIX for Dummies Questions & Answers

find Search - Find files not matching a pattern

Hello all, this is my first and probably not my last question around here. I do hope you can help or at least point me in the right direction. My question is as follows, I need to find files and possible folders which are not owner = AAA group = BBB with a said location and all sub folders ... (7 Replies)
Discussion started by: kilobyter
7 Replies

5. Shell Programming and Scripting

what is the find to command to find the files created last 30 days

what is the find to command to find the files created last 30 days (5 Replies)
Discussion started by: rajkumar_g
5 Replies

6. Shell Programming and Scripting

Find and Rename files using (find mv and sed)

In response to a closed thread for degraff63 at https://www.unix.com/shell-programming-scripting/108882-using-mv-find-exec.html the following command might do it as some shells spit it without the "exec bash -c " part: Find . -name "*.model" -exec bash -c "mv {} \`echo {} | sed -e 's//_/g'\`"... (0 Replies)
Discussion started by: rupert160
0 Replies

7. Shell Programming and Scripting

Compare 2 folders to find several missing files among huge amounts of files.

Hi, all: I've got two folders, say, "folder1" and "folder2". Under each, there are thousands of files. It's quite obvious that there are some files missing in each. I just would like to find them. I believe this can be done by "diff" command. However, if I change the above question a... (1 Reply)
Discussion started by: jiapei100
1 Replies

8. Shell Programming and Scripting

Can I know find syntax to find given date files

Hi All, Can i use find command to know given date files? If yes, then please let me know the syntax for the same. Thanks in advance for your postive responses Regards, Bachegowda (3 Replies)
Discussion started by: bache_gowda
3 Replies

9. Shell Programming and Scripting

Little bit weired : Find files in UNIX w/o using find or where command

Yes , I have to find a file in unix without using any find or where commands.Any pointers for the same would be very helpful as i am beginner in shell scritping and need a solution for the same. Thanks in advance. Regards Jatin Jain (10 Replies)
Discussion started by: jatin.jain
10 Replies

10. Shell Programming and Scripting

Find files older than 20 days & not use find

I need to find files that have the ending of .out and that are older than 20 days. However, I cannot use find as I do not want to search in the directories that are underneath the directory that I am searching in. How can this be done?? Find returns files that I do not want. (2 Replies)
Discussion started by: halo98
2 Replies
Login or Register to Ask a Question