The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 4.00 average. Display Modes
  #1 (permalink)  
Old 08-24-2007
prvnrk prvnrk is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 138
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
  #2 (permalink)  
Old 08-24-2007
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
Do something like this---

mv file1.txt.txt* file1.txt
mv file2.txt.txt* file2.txt

or

sed s/file1.txt.txt*/file1.txt

Thanks
Namish
  #3 (permalink)  
Old 08-24-2007
summer_cherry summer_cherry is online now Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,079
!!!!!!!!!!!!

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,".")))
}'
  #4 (permalink)  
Old 08-24-2007
prvnrk prvnrk is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 138
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"..
  #5 (permalink)  
Old 08-24-2007
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
Quote:
Originally Posted by prvnrk View Post
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"..
Summer_cherry is just doing a echo of number,nothing to do with number that is not a variable.Whatever you do with echo that is excatly printed again.If you do not understand the code let me know i will tell you.

Thanks
Namish
  #6 (permalink)  
Old 08-24-2007
prvnrk prvnrk is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 138
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
  #7 (permalink)  
Old 08-24-2007
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
suppose you enterd num as 5,then it will print a file that is having a extension of
file1.txt.txt.txt.txt.txt
and reduce it to
file1.txt
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:51 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0