Finding the files and count then


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Finding the files and count then
# 1  
Old 05-23-2013
Finding the files and count then

Hi i was trying to find the files which are not older than one day and copy them to other location . but i need to count the number of files and the copy them if the count is matches my number

Code:
A=`find $SOURCE/* -type f -mtime -1 `

in the code above i need to count the number of file A has (it should be 6) .if the number macthes i would copy else i would exit. i thought of usnig some thing like if count =6 then copy kind of thing. Any ideas would be appericated
# 2  
Old 05-23-2013
Try assigning an array and then testing its element count:
Code:
$ A=( $(ls) )
$ echo "${#A[*]}"
16

# 3  
Old 05-23-2013
RudiC, I think that approach will cause discrepancies in count if there are file names with blank space. Isn't that right?
# 4  
Old 05-23-2013
Hi i tried this,but didnt work


Code:
#!/bin/bash
A=`find /path/to/files/* -type f -mtime -1 `
if [ "${#A[*]}" -eq 6 ]
then
something here
fi

# 5  
Old 05-23-2013
Quote:
Originally Posted by Yoda
RudiC, I think that approach will cause discrepancies in count if there are file names with blank space. Isn't that right?
Yes, filenames with spaces will cause trouble. Try this:
Code:
$ IFS=$'\n' A=( $(ls -1) )
$ echo ${#A[*]}
13

Quote:
Originally Posted by vikatakavi
Hi i tried this,but didnt work
. . .
It can't, because you didn't do what I proposed. You did not assign an array.
# 6  
Old 05-23-2013
Hi Rudic ,

Code:
#!/bin/bash
A=`find /path/to/files/* -type f -mtime -15 `
IFS=$'\n' A=( $(ls -1) )
echo ${#A[*]}

it returned 63 ,i am not sure for what that value is for

Last edited by vikatakavi; 05-23-2013 at 05:20 PM..
# 7  
Old 05-23-2013
Try assigning to an array (but take care of spaces in filenames!):
Code:
A=( $(find /path/to/files/* -type f -mtime -15) )

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding total distinct count from multiple csv files through UNIX script

Hi All , I have multiple pipe delimited csv files are present in a directory.I need to find out distinct count on a column on those files and need the total distinct count on all files. We can't merge all the files here as file size are huge in millions.I have tried in below way for each... (9 Replies)
Discussion started by: STCET22
9 Replies

2. Shell Programming and Scripting

Shell script for field wise record count for different Files .csv files

Hi, Very good wishes to all! Please help to provide the shell script for generating the record counts in filed wise from the .csv file My question: Source file: Field1 Field2 Field3 abc 12f sLm 1234 hjd 12d Hyd 34 Chn My target file should generate the .csv file with the... (14 Replies)
Discussion started by: Kirands
14 Replies

3. Shell Programming and Scripting

Error files count while coping files from source to destination locaton as well count success full

hi All, Any one answer my requirement. I have source location src_dir="/home/oracle/arun/IRMS-CM" My Target location dest_dir="/home/oracle/arun/LiveLink/IRMS-CM/$dc/$pc/$ct" my source text files check with below example.text file content $fn "\t" $dc "\t" $pc "\t" ... (3 Replies)
Discussion started by: sravanreddy
3 Replies

4. Shell Programming and Scripting

Finding a certain character in a filename and count the characters up to the certain character

Hello, I do have folders containing having funny strings in their names and one space. First, I do remove the funny strings and replace the space by an underscore. find . -name '* *' | while read file; do target=`echo "$file" | sed 's/... (2 Replies)
Discussion started by: tempestas
2 Replies

5. Shell Programming and Scripting

Finding total count of a word.

i want to find the no:of occurrences of a word in a file cat 1.txt unix script unix script unix script unix script unix script unix script unix script unix script unix unix script unix script unix script now i want to find , how many times 'unix' was occurred please help me thanks... (6 Replies)
Discussion started by: mahesh1987
6 Replies

6. Red Hat

finding CPU count - reading sysinfo output

Hello, sysinfo throws out below 3 CPU counts. Can anyone help me understand what each of these means? CPU Count Socketed is 2 CPU Count Physical is 8 CPU Count Virtual is 16 First one seems obvious. However, I wonder how there can be 8 Physical CPUs, if... (2 Replies)
Discussion started by: hnhegde
2 Replies

7. Shell Programming and Scripting

Finding most repeated entry in a column and giving the count

Please can you help in providing the most repeated entry in the 2nd column and give its count Here is an input file 1, This , is a forum 2, This , is a forum 1, There , is a forum 2, This , is not right Here the most repeated entry is "This" and count is 3 So output... (4 Replies)
Discussion started by: necro98
4 Replies

8. Shell Programming and Scripting

Finding files with wc -l results = 1 then moving the files to another folder

Hi guys can you please help me with a script to find files with one row/1 line of content then move the file to another directory my script below runs but nothing happens to the files....Alternatively Ca I get a script to find the *.csv files with "wc -1" results = 1 then create a list of those... (5 Replies)
Discussion started by: Dj Moi
5 Replies

9. Shell Programming and Scripting

finding field count escaping the blank values

Hi All I have a file.Below are few records of the file. sample.txt CPS,ES,843232910001,ESF81462,W N LINDSAY LTD,01674840629,09-FEB-2009,23-FEB-2009,CDR735,ALL CALLS,01674840629 CPS,ES,843232670001,ESF81462,W N LINDSAY LTD,01674840629,09-FEB-2009,23-FEB-2009,CDR734,ALL... (2 Replies)
Discussion started by: king007
2 Replies

10. Shell Programming and Scripting

finding duplicate files by size and finding pattern matching and its count

Hi, I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern. Note:These are the samples of two files,but i can have more... (2 Replies)
Discussion started by: jerome Sukumar
2 Replies
Login or Register to Ask a Question