Unix/Linux Go Back    

Debian Debian GNU/Linux is a free distribution of the GNU/Linux operating system.

Changing file extension names


Thread Tools Search this Thread Display Modes
Old Unix and Linux 07-17-2017   -   Original Discussion by anaigini45
anaigini45's Unix or Linux Image
anaigini45 anaigini45 is offline
Registered User
Join Date: Oct 2009
Last Activity: 18 January 2018, 9:12 AM EST
Posts: 102
Thanks: 4
Thanked 0 Times in 0 Posts
Changing file extension names

Hi I have a list of files :

root@L28mustang:/var/log/exim4/2017/Jul2017_Blast_BC07# ls -lrt | grep mainlog
-rw-r----- 1 Debian-exim adm  3636932 Jul  8 06:25 mainlog.3.gz
-rw-r----- 1 Debian-exim adm   919512 Jul  9 06:27 mainlog.2.gz
-rw-r----- 1 Debian-exim adm  7655054 Jul 10 06:25 mainlog.1
-rw-r----- 1 Debian-exim adm  2799218 Jul 10 15:40 mainlog

I need to change the extension names for all the files above to .filtered.
I know how to do it for the .gz files like this :

for i in mainlog*
	   exigrep L28stream1 "$i" | egrep -v "jiun.shyong.hor@ericsson.com|chander.c.shekher@ericsson.com|nagios|L28eagle" > "${i/%.gz/.filtered}"

How do I change both the mainlog files with the .gz extension and without the .gz extension in one command?

Last edited by rbatte1; 07-17-2017 at 12:33 PM.. Reason: Code tags
Sponsored Links
Old Unix and Linux 07-17-2017   -   Original Discussion by anaigini45
MadeInGermany's Unix or Linux Image
MadeInGermany MadeInGermany is offline Forum Staff  
Join Date: May 2012
Last Activity: 23 January 2018, 6:57 AM EST
Location: Simplicity
Posts: 3,950
Thanks: 335
Thanked 1,325 Times in 1,195 Posts
Strip a .gz and add .filtered

... > "${i%.gz}.filtered"

Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Changing file names kristinu Shell Programming and Scripting 3 04-01-2014 02:11 PM
Changing file extension in csh alias ygmwayne Shell Programming and Scripting 1 09-28-2012 04:41 AM
Changing file extension jaysean UNIX for Dummies Questions & Answers 4 07-16-2010 04:31 AM
changing file extension spidydude UNIX for Dummies Questions & Answers 6 02-17-2009 03:21 AM
Changing the extension of the file mazhar803 UNIX for Dummies Questions & Answers 4 08-29-2008 10:20 AM

All times are GMT -4. The time now is 09:53 AM.