User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 391,779 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,458 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser:
Views: 955 | Replies: 7
Reply
Join Date: Oct 2005
Posts: 6
Reputation: pichels is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
pichels pichels is offline Offline
Newbie Poster

Script to list dir path and count characters?

  #1  
Apr 30th, 2008
Hi,

I need to search a large Directory Path and count all the characters(Even filenames with space and special chars, etc.) in it.
Example:

/data/general\Customer_Order_Files\Pump_Files\Pump_Open_Files\1217697 METSO MINERALS HITACHI AMERON DUCK CREEK\1217697 MOTOR INFO METSO MIN HITACHI AMER DUCK CREEK 10-3-06\1217697 Motor Quote SIEMENS METSO MIN HIT AMER DUCK CREEK 10-16-06 .pdf

We are trying to search all Directory paths that users have created and limit them to 240 chars or 10 Directory levels and 24 chars per Directory or Filename for a full character count of 240.

Why you ask? <smile>
We have encountered issues trying to copy the above file path to a Windows 2003 server from Linux via Samba share.

Any help is greatly appreciated!

Thanks.

SP
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2005
Posts: 3,261
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 20
Solved Threads: 368
Colleague
Salem's Avatar
Salem Salem is offline Offline
void main'ers are DOOMed

Re: Script to list dir path and count characters?

  #2  
May 1st, 2008
find . - type f | awk -F/ '$NF > 10 && length($0) > 240 { print "Bad\n" }'
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Reply With Quote  
Join Date: Oct 2005
Posts: 6
Reputation: pichels is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
pichels pichels is offline Offline
Newbie Poster

Re: Script to list dir path and count characters?

  #3  
May 1st, 2008
Hi Salem,

A great example but how do I list the directory's instead of printing "bad"?
Also, can I print out results with number of characters like:

/data/general/... : 230 chars

I appreciate your help!
TIA.

SP

Originally Posted by Salem View Post
find . - type f | awk -F/ '$NF > 10 && length($0) > 240 { print "Bad\n" }'
Reply With Quote  
Join Date: Oct 2007
Posts: 256
Reputation: eggi is on a distinguished road 
Rep Power: 1
Solved Threads: 26
eggi eggi is offline Offline
Posting Whiz in Training

Re: Script to list dir path and count characters?

  #4  
May 1st, 2008
Hey There,

You can print out the name of the found file by printing out $0 and the number of characters by printing NF -- You'll be doing both within the awk statement and it's important to print NF for the number. If you print $NF you'll get the value of the last field.

Hope that helps

, Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
Reply With Quote  
Join Date: Dec 2005
Posts: 3,261
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 20
Solved Threads: 368
Colleague
Salem's Avatar
Salem Salem is offline Offline
void main'ers are DOOMed

Re: Script to list dir path and count characters?

  #5  
May 2nd, 2008
As with many of my posts, it's not an answer which you can simply copy/paste into your problem and expect it to work.

It's to show you what's possible in the hope that you'll then be able to apply that new insight to your own problem in your own way, and in the process learn something.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Reply With Quote  
Join Date: Oct 2005
Posts: 6
Reputation: pichels is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
pichels pichels is offline Offline
Newbie Poster

Re: Script to list dir path and count characters?

  #6  
May 2nd, 2008
Originally Posted by Salem View Post
As with many of my posts, it's not an answer which you can simply copy/paste into your problem and expect it to work.

It's to show you what's possible in the hope that you'll then be able to apply that new insight to your own problem in your own way, and in the process learn something.


Hi Salem,

Yes, I understand, I 'll give more details from now on.
Thanks for your info. I did figure it out on my own after posting in a panic for time. <smile>


SP
Reply With Quote  
Join Date: Oct 2005
Posts: 6
Reputation: pichels is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
pichels pichels is offline Offline
Newbie Poster

Re: Script to list dir path and count characters?

  #7  
May 2nd, 2008
Thanks for the answer Eggi and the answer.
Sorry to be pest...

SP
Reply With Quote  
Join Date: Oct 2007
Posts: 256
Reputation: eggi is on a distinguished road 
Rep Power: 1
Solved Threads: 26
eggi eggi is offline Offline
Posting Whiz in Training

Re: Script to list dir path and count characters?

  #8  
May 2nd, 2008
Glad to help

Apologies if I overstepped any forum boundaries. As luck would have it, I didn't provide a cut-and-paste answer either

, Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Shell Scripting Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 4:53 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC