![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#8
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#9
|
|||
|
|||
|
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" }'
|
|
#10
|
|||
|
|||
|
Quote:
Code:
fName="abcdXXXXXX.pqrXXXXX.asc"
echo ${fName%.*}
|
|
#11
|
|||
|
|||
|
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! |
|
#12
|
|||
|
|||
|
Quote:
Code:
find / | grep -E --regexp=[^/]\{n,\}
|
|||
| Google The UNIX and Linux Forums |
| Thread Tools | |
| Display Modes | |
|
|