- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script Needed to Count Characters in a filename
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2007 03:54 AM
тАО05-08-2007 03:54 AM
The new system has a character limit of 128 for a filename, and I know some files on the old system exceed this.
Does anyone have a script that could loop through my system and generate a log file of all file names that are longer than 128 characters?
TIA...
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2007 04:09 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2007 04:12 AM
тАО05-08-2007 04:12 AM
Re: Script Needed to Count Characters in a filename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2007 04:14 AM
тАО05-08-2007 04:14 AM
Re: Script Needed to Count Characters in a filename
to
HPUX 11.23 w/(UTF) remote storage
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2007 04:26 AM
тАО05-08-2007 04:26 AM
Re: Script Needed to Count Characters in a filename
it's not clear if you mean, that the full pathname may not exceed this limit or just a plain filename.
Plain filename <128 chars will be reported by
find . | awk -F/ 'length($NF) >=128'
A directory having a name >= 128 will be reported only once - so you can use this list as an input for a renaming script.
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2007 04:37 AM
тАО05-08-2007 04:37 AM
Re: Script Needed to Count Characters in a filename
Pathname = /home/bob1/docs/file1
Filename = file1
It doesnt matter if the pathname all together exceeds 128 characters, but the filename must not exceed 128 characters.
I also need to account for white spaces in the filenames, and to be able to count the whitespace as a character.
File example: Job Advertising Listing.qxd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2007 04:46 AM
тАО05-08-2007 04:46 AM
Re: Script Needed to Count Characters in a filename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2007 04:48 AM
тАО05-08-2007 04:48 AM
Re: Script Needed to Count Characters in a filename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2007 04:50 AM
тАО05-08-2007 04:50 AM
Re: Script Needed to Count Characters in a filename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2007 04:55 AM
тАО05-08-2007 04:55 AM
Re: Script Needed to Count Characters in a filename
find . -exec basename {} \; | awk '{if (length($0) > 128) {print $0}}'
becomes:
find . -exec basename "{}" \; | awk '{if (length($0) > 128) {print $0}}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2007 04:59 AM
тАО05-08-2007 04:59 AM
Re: Script Needed to Count Characters in a filename
.:basename./Thankyou/Thankyoucards report:No such file or directory
bash-2.05a# find . -name 'Thankyoucards report'
./Thankyou/Thankyoucards report
I am not really familiar with the basename function....do it have a problem with relative paths perhaps?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2007 05:15 AM
тАО05-08-2007 05:15 AM
Re: Script Needed to Count Characters in a filename
WRONG! WRONG! WRONG! (3 wrongs don't make it right.)
Wrong No. 1: Note no whitespace between basename and ./Thankyou... so the shell is looking for
basename./Thankyou/Thankyoucards and that command can't be found.
Wrong No. 2: No quotes so "report" is treated as a suffix argument to basename
Wrong No. 3: Basename is a command not a function. Man basename for details.
The final example where I placed {} inside double quotes should do just what you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2007 05:19 AM
тАО05-08-2007 05:19 AM
Re: Script Needed to Count Characters in a filename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2007 05:24 AM
тАО05-08-2007 05:24 AM
Re: Script Needed to Count Characters in a filename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2007 08:53 PM
тАО05-08-2007 08:53 PM
Re: Script Needed to Count Characters in a filename
my one-liner meets all your requests as well, IMHO.
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2007 11:27 PM
тАО05-08-2007 11:27 PM
Re: Script Needed to Count Characters in a filename
FULLPATH="long/path/name/with/special File name"
NAMEONLY="${FULLPATH##*/}"
NAMELENGTH=${#NAMEONLY}
Notice the use of ".." marks to include any embedded spaces. If you need to check whether a filename has imbedded spaces or other special characters, use the class matching available in tr. You can remove all the 'normal' characters and if anything is left, the filename contains sp[ecial characters:
[ "$(echo "$NAMEONLY" | tr -d '[:alnum:]')" != "" ] && echo "filename has non-alphanumeric chars"
By using shell built-ins, the overhead in calling external routines is eliminated. Here are some shell constructs that replace external commands:
basename MYPATH
${MYPATH##*/}
dirname MYPATH
${MYPATH%*/}
To reduce fully qualified domain names such as cpu1.mysite.com to just cpu1:
MYCPU=cpu1.mysite.com
${MYCPU%%.*}
To parse out the 4 numbers in a network address:
MYADDR=1.23.45.67
echo $MYADDR | IFS=. read ADDR1 ADDR2 ADDR3 ADDR4
echo $ADDR1 $ADDR2 $ADDR3 $ADDR4
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2007 09:31 AM
тАО07-12-2007 09:31 AM