Count caraters on filename


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Count caraters on filename
# 1  
Old 02-11-2008
Count caraters on filename

Hello people.

I need some help to do this:

I've got some files that i need to count the caracters of filenames.

20080209_2000591574_237004076372.xml
20080202_1360584_267002636042.xml

The minimum is 15 . If some file with less must move them to another directory.

Obviously these files always have different names.

I was doing this but only i get them names, bus i can't do the count:

lista=`ls`

for file in $lista
do

new_name=`echo $file |awk '{print substr($0,1,length($0))}'`


done

Can anyone help me ?

Regards
# 2  
Old 02-11-2008
how about:

Code:
 echo 20080209_2000591574_237004076372.xml | wc -c
      37

# 3  
Old 02-11-2008
Code:
for f in *.xml;do ((${#f}<15))&&mv "$f" other_dir;done

If you want to exclude the extension and it's not fixed:

Code:
for f in *;do 
  fn="${f%.}"
  ((${#fn}<15))&&mv "$f" other_dir
done

# 4  
Old 02-11-2008
Hy Titalus

i made this script with you example:

lista=`ls`

for file in $lista
do
new_name=`echo $file |awk '{print length($0)}'`

if [ $new_name < 15 ]

then
cp $file $DIR_TESTE
fi
done;

But it gaves this error:

A file or directory in the path name does not exist.
./arruma.sh[15]: 15: 0403-016 Cannot find or open the file.

What's the problem ?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to find the count of IP addresses that belong to different subnets and display the count?

Hi, I have a file with a list of bunch of IP addresses from different VLAN's . I am trying to find the list the number of each vlan occurence in the output Here is how my file looks like 1.1.1.1 1.1.1.2 1.1.1.3 1.1.2.1 1.1.2.2 1.1.3.1 1.1.3.2 1.1.3.3 1.1.3.4 So what I am trying... (2 Replies)
Discussion started by: new2prog
2 Replies

2. Shell Programming and Scripting

To count underscore in filename

Hi All I have a filename like below adsf_ghjt_kop_pol.csv Can you please get me a command for counting the number of underscore in the filename. In the above filename I should get output as 3, since the file name is having three underscore (5 Replies)
Discussion started by: ginrkf
5 Replies

3. Shell Programming and Scripting

File Count and FileName

Hi I have a set of files in one directory like below FIN_TASK1.csv FINA_TASK2.csv FIN_TASK3.csv. I want a command to print the count in each file and the correspong file name into one file.My expected output is given below cat filcount.txt 2 "FIN_TASK1.csv" 4 "FIN_TASK2.csv" ... (3 Replies)
Discussion started by: ginrkf
3 Replies

4. Shell Programming and Scripting

Compare file1 header count with file2 line count

What I'm trying to accomplish. I receive a Header and Detail file for daily processing. The detail file comes first which holds data, the header is a receipt of the detail file and has the detail files record count. Before processing the detail file I would like to put a wrapper around another... (4 Replies)
Discussion started by: pone2332
4 Replies

5. 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

6. Programming

to extract all the part of the filename before a particular word in the filename

Hi All, Thanks in Advance I am working on a shell script. I need some assistance. My code: if then set "subscriber" "promplan" "mapping" "dedicatedaccount" "faflistSub" "faflistAcc" "accumulator"\ "pam_account"; for i in 1 2 3 4 5 6 7 8;... (0 Replies)
Discussion started by: aealexanderraj
0 Replies

7. UNIX for Dummies Questions & Answers

to extract all the part of the filename before a particular word in the filename

Hi All, Thanks in Advance I am working on a shell script. I need some assistance. My Requirement: 1) There are some set of files in a directory like given below OTP_UFSC_20120530000000_acc.csv OTP_UFSC_20120530000000_faf.csv OTP_UFSC_20120530000000_prom.csv... (0 Replies)
Discussion started by: aealexanderraj
0 Replies

8. Shell Programming and Scripting

Filename pattern count

Hi I have the following files in a directory - ds_pl_W_Test ds_pl_list_Test ds_pl_list_Test ds_pl_listl_Test ds_pl_file_Test ds_pl_xx_Test I would like to count the number files in the directory that contain the word "list" I tried the following but it returns zero - ... (3 Replies)
Discussion started by: Prega
3 Replies

9. Shell Programming and Scripting

Filename from splitting files to have the same filename of the original file with counter value

Hi all, I have a list of xml file. I need to split the files to a different files when see the <ko> tag. The list of filename are B20090908.1100-20090908.1200_CDMA=1,NO=2,SITE=3.xml B20090908.1200-20090908.1300_CDMA=1,NO=2,SITE=3.xml B20090908.1300-20090908.1400_CDMA=1,NO=2,SITE=3.xml ... (3 Replies)
Discussion started by: natalie23
3 Replies

10. Shell Programming and Scripting

gzcat into awk and then change FILENAME and process new FILENAME

I am trying to write a script that prompts users for date and time, then process the gzip file into awk. During the ksh part of the script another file is created and needs to be processed with a different set of pattern matches then I need to combine the two in the end. I'm stuck at the part... (6 Replies)
Discussion started by: timj123
6 Replies
Login or Register to Ask a Question