The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Truncate Log files anonymous1 Shell Programming and Scripting 1 10-21-2007 04:05 PM
*** Truncate certain field *** sannmayaz UNIX for Advanced & Expert Users 2 08-15-2007 07:14 AM
Truncate File contain rinku Shell Programming and Scripting 2 05-30-2007 03:43 AM
How to truncate as filesize? Lestat Shell Programming and Scripting 1 06-07-2005 12:24 PM
Truncate what is It? rocker40 UNIX for Dummies Questions & Answers 2 10-11-2003 04:40 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #8  
Old 07-31-2007
Registered User
 

Join Date: May 2007
Posts: 23
Hi Folks,

I just wanted to add something to the original problem,
What will i do if, i am not sure about the length of the file name, but only one thing that i want to remove only the last extension.
e.g. abcdXXXXXX.pqrXXXXX.asc (X is any character)
I want to trim only .asc (or,watever) so that resultant file name would be like abcdXXXXX.pqrXXXXX
Reply With Quote
Forum Sponsor
  #9  
Old 07-31-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,609
this,

Code:
echo "abcdXXXXXX.pqrXXXXX.asc" | awk -F"." '{ for ( i=1; i<NF; i++) { printf "%s", $i; if ( i < NF - 1 ) { printf "%s", "." } } printf "\n" }'
Reply With Quote
  #10  
Old 07-31-2007
Registered User
 

Join Date: May 2007
Posts: 211
Quote:
Originally Posted by vishal_ranjan View Post
e.g. abcdXXXXXX.pqrXXXXX.asc (X is any character)
I want to trim only .asc (or,watever) so that resultant file name would be like abcdXXXXX.pqrXXXXX
Code:
fName="abcdXXXXXX.pqrXXXXX.asc"
echo ${fName%.*}
Reply With Quote
  #11  
Old 07-30-2008
Registered User
 

Join Date: Jul 2008
Posts: 2
Thumbs down

Here's a more complex challenge (though not an arbitrary one)...

A user has many files with names that are too long, and they must be truncated to n characters, however the first n characters are the same. Can someone post a script that truncates to n-k characters and then counts up with k digits or uses k random characters, so as to avoid overwriting files?

Example:

really-long-filename-a.dat
really-long-filename-b.dat

Would be converted to:

really-long-fi_001.dat
really-long fi_002.dat

or

really-long-fi_vj3.dat
really-long-fi_w4p.dat


Another piece of code that would be very useful (and simpler I imagine) would be something that simply identifies which filenames located within a specified part of the filesystem have names in excess of n characters. Seems like a find piping into grep should do the trick. Some use of the {n,} operator would be involved... never had occasion to get my feet that wet with regexes.

Cheers!
Reply With Quote
  #12  
Old 07-30-2008
Registered User
 

Join Date: Jul 2008
Posts: 2
Quote:
Originally Posted by gumpish View Post
Another piece of code that would be very useful (and simpler I imagine) would be something that simply identifies which filenames located within a specified part of the filesystem have names in excess of n characters.
Well that was easy enough...

Code:
find / | grep -E --regexp=[^/]\{n,\}
An intelligent truncator would still be nifty though.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:16 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0