![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Stripping out extensions when file has multiple dots in name | Nemelis | Shell Programming and Scripting | 8 | 05-14-2008 08:12 AM |
| Truncate last <n> characters from a file | Gwailo88 | UNIX for Dummies Questions & Answers | 1 | 03-05-2008 12:52 AM |
| Truncate File contain | rinku | Shell Programming and Scripting | 2 | 05-30-2007 06:43 AM |
| how to truncate a large (8 GB) file | kotasateesh | Shell Programming and Scripting | 1 | 07-05-2006 01:57 AM |
| find -regex: matching multiple extensions | r0sc0 | Shell Programming and Scripting | 2 | 12-08-2005 02:32 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
|
|
||||
|
Truncate multiple file extensions
Hi,
I have files with names like file1.txt.txt.txt.txt and file2.txt.txt.txt.txt.txt............ (random infinite number of .txt exist). how to truncate (mv) their names to ones with single .txt extension like file1.txt and file1.txt ? In other words, how to extract the filename upto first extension part? Txs Prvn |
|
||||
|
!!!!!!!!!!!!
Hi try this one:
Code:
echo "number"
read num
who | nawk -v n=$num 'BEGIN{
str="file"
for (i=1;i<=n;i++)
str=sprintf("%s%s",str,".txt")
}
END{
print str
printf("%stxt\n",substr(str,1,index(str,".")))
}'
|
|
||||
|
Txs namishtiwari,
But i have to do this for thousands of files in a directory so i cant use hardcoded filename. i will be using for loop for reading each file name. So, here how could i extract the "filename with first extension" out of "filename with infinite extensions"? txs summer_cherry, here i dont know what is "number".. |
|
||||
|
Quote:
Thanks Namish |
|
||||
|
Namish,
I know what " echo "number" " does and there's nothing hard to understand there. But his code expects again a "num". I'm not sure if you read my post fully and again i repeat "how could i extract the "filename with first extension" out of "filename with infinite extensions"?" e.g., how to extract "file1.txt" from file1.txt.txt.txt..........? (no hardcoding of filenames with wild char pls..) Regards, Prvn |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|