find only 6 char long


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find only 6 char long
# 1  
Old 10-11-2012
find only 6 char long

HTML Code:
find /tmp -type f -mtime +180 
I have this script get the list to clean up files older than 180 days under /tmp.
But, I want to make sure to grep only a type of files, which have only 6 character long.

HTML Code:
....
LT3hqa                               dRMoya                               zZefaa
LTAeia                               dRahaa                               zZqbaa
LTIkMa                               dRqbaa                               zlQeEa
LTenMa                               dRunia                               zlqgEa
LTmlqa                               dSEeUa                               zoaaya
LV3nEa                               dSMb7a                               zpYhia
LV7caa                               dSYiqa                               zpqgUa
LVAp7a                               dSaaEa                               zvmpaa
LVYjUa                               dSacya                               zw3cMa
LVqbaa                               dSmnia                               zzAmaa
LVylqa                               dTAeaa
LWmbia                               dTEfMa
...
Please advise how to
HTML Code:
find
files with 6-charactor long and 180 days old.
# 2  
Old 10-11-2012
This should work:

Code:
find /tmp -type f -mtime +180 | grep '^.\{6\}$'

# 3  
Old 10-11-2012
Quote:
Originally Posted by Subbeh
This should work:

Code:
find /tmp -type f -mtime +180 | grep '^.\{6\}$'

It returns nothing.

If I just run
PHP Code:
find /tmp -type f -mtime +180 
, I am getting these outputs.
HTML Code:
....
/tmp/yZqcMa
/tmp/yZyiya
/tmp/y_Mdia
/tmp/y_Qcia
/tmp/y_Qcya
/tmp/y_ap7a
/tmp/y_mkia
/tmp/y_qfUa
/tmp/y_yc7a
/tmp/ypMe7a
/tmp/ypYk7a
/tmp/yxAi7a
....
Is it the reason??
Please advise.
# 4  
Old 10-11-2012
Yes, just add 5 more characters to include /tmp/:

Code:
find /tmp -type f -mtime +180 | grep '^.\{11\}$'

# 5  
Old 10-11-2012
try this..

Code:
find /tmp -type f -mtime +180 | awk -F/ 'length($NF) == 6'

# 6  
Old 10-11-2012
Quote:
Originally Posted by pamu
try this..

Code:
find /tmp -type f -mtime +180 | awk -F/ 'length($NF) == 6'

It pulls out:
PHP Code:
olympus:/> find /tmp -type f -mtime +180 awk -F'length($NF) == 6'
/tmp/.alist
/tmp/EFILE1
/tmp/acsisvc/f88c1119/.inuse
/tmp/acsisvc/f88c1119/sdscan
/tmp/diagSEgenSnap/general/errlog
/tmp/diagSEgenSnap/general/ike.db
/tmp/diagSEgenSnap/general/lsfilt
/tmp/diagSEgenSnap/general/trcfmt
/tmp/ecfile
/tmp/ibmsupt/general/trcfmt
/tmp/ibmsupt/tcpip/rc.net
/tmp/ibmsupt/tcpip/rc.qos
/tmp/prereq
..... 
It should have pulled out:
PHP Code:
/tmp/.alist
/tmp/EFILE1
/tmp/ecfile
/tmp/prereq
.. 
which only 6 character long followed by /tmp/

Please advise.
# 7  
Old 10-11-2012
Try it the simple/stupid findless and egrepless way:
Code:
ls -a /tmp/ | grep '^......$'

It won't add /tmp/ to the names.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find command take too long

Hi, I use the below script that will find n record the entire directory structure for a given folder. bash-3.2$ more mkdir.sh find . -type d |while read rec do echo "mkdir $rec" echo "chmod -R 777 $rec" #done done >> moht.sh The problem is the folder i m running this script... (10 Replies)
Discussion started by: mohtashims
10 Replies

2. Shell Programming and Scripting

To find char field and replace null

hi, i having a file with | seperated in which i need to search char in 3rd column and replace with null. i need to replace only the coulmn where character occurs in 3rd field for eg: file1.txt xx|yy|xx|12 output file: xx|yy||12 (5 Replies)
Discussion started by: rohit_shinez
5 Replies

3. Shell Programming and Scripting

Find and replace all extended char.

Hi Guys, I wand find and replace all Extended ASCII Codes from all my log files. My Log files: /home/Kalr/PPool/Output i have logs file in sub dir. /home/Kalr/PPool/Output/X /home/Kalr/PPool/Output/Y /home/Kalr/PPool/Output/Z My Abc.log file input: Extended ASCII Codes :– ... (4 Replies)
Discussion started by: asavaliya
4 Replies

4. Shell Programming and Scripting

cutting long text by special char around 100 byte and newline

Regard, How can i cut the text by special char(|) around 100 byte and write the other of the text at newline using Perl. ... (3 Replies)
Discussion started by: Shawn, Lee
3 Replies

5. Programming

Help with understanding ( int, char, long, short, signed, unsigned etc.... )

My question is simple: When should I use a long, int, char, unsigned/signed variables?? When I declare a variable "unsigned;" what did I do it??? Why would I delcare an integer "long" or "short" ( unsigned or signed)?? Any examples of when things like "unsigned", "long", "short" etc...... (6 Replies)
Discussion started by: cpp_beginner
6 Replies

6. Programming

How to find length of string and pass into char array in C?

Hi All I want to take a Hexadecimal number as input and i want to find lenth of the input and pass it to char s ( char s ). I have a program to convert hexadecial to binary but it is taking limited input but i want to return binary number based on input. How? (1 Reply)
Discussion started by: atharalikhan
1 Replies

7. Shell Programming and Scripting

Line gets splitted into 99 char long pieces

Hello, I have a script like follows. It reads a file, and with every line, it calls an "adapter" program, which just puts the line into MQ. When I run this locally, it works fine. When I run this on our company's server, one line is split into several pieces (99 characters long) and "adapter"... (1 Reply)
Discussion started by: Adamm
1 Replies

8. Shell Programming and Scripting

To find number of char occur

To find out number of "|" symbol is available in file: Input: a|b|c|d|z Ouput: 4 I am using below set of commands,It is working... Anybody have anyother solution using sed / awk. cnt=`wc -c <1.txt` cnt1=`tr -d "|" <1.txt >c.dat` cnt2=`wc -c <c.dat` outp=`expr $cnt... (19 Replies)
Discussion started by: Jairaj
19 Replies

9. Shell Programming and Scripting

grep : search a long char contain space

Hi, i have to search for a char like that : export var1="i am not happy /not happy" with a command like : grep $var1 file but this not working with me !!! thank you in advance. (2 Replies)
Discussion started by: tizilfin
2 Replies

10. Shell Programming and Scripting

command find returned bash: /usr/bin/find: Argument list too long

Hello, I create a file touch 1201093003 fichcomp and inside a repertory (which hava a lot of files) I want to list all files created before this file : find *.* \! -maxdepth 1 - newer fichcomp but this command returned bash: /usr/bin/find: Argument list too long but i make a filter all... (1 Reply)
Discussion started by: yacsil
1 Replies
Login or Register to Ask a Question