LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-18-2010, 04:19 PM   #1
gubbu
LQ Newbie
 
Registered: Dec 2009
Posts: 10

Rep: Reputation: 0
split a gzip file based on size and have a prefix without changing extension


I have a gzip file

ABC_000023232.gzip
BCD_023232032.gzip

I want to split these files into smaller files but keep the extension same because I am using this as a variable in a script

Code:
for i in `ls *.gzip`
split -b 500K $i $i
done
This produces
Code:
ABC_000023232.gzipaa
ABC_000023232.gzipab
ABC_000023232.gzipac
BCD_023232032.gzipaa
BCD_023232032.gzipac
I want
Code:
ABC_000023232aa.gzip
ABC_000023232ab.gzip
ABC_000023232ac.gzip
BCD_023232032aa.gzip
BCD_023232032ab.gzip
 
Old 01-18-2010, 04:53 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Code:
wanted=`echo $i|cut -d'p' -f2`
fname=`echo $i|cut -d'.' -f1`
new=${fname}${wanted}.gzip
quick 'n 'dirty
 
Old 01-18-2010, 05:07 PM   #3
gubbu
LQ Newbie
 
Registered: Dec 2009
Posts: 10

Original Poster
Rep: Reputation: 0
Not sure I understand . Are you asking to rename he files with your logic ?
 
Old 01-18-2010, 05:09 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Yep; that code generates the new name for each file as it goes, then add a mv cmd.
Try it on one or two file (backup copies) to see how it works.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Split a gzip file ZAMO Linux - Server 6 08-21-2012 10:30 AM
split file based on number of string apperance mcbenus Programming 10 12-24-2009 06:44 PM
compress file size bigger than uncompress in gzip format kumartnj Linux - General 1 04-10-2009 02:28 AM
bash: renaming file extension based on actual file type alekone Linux - General 9 12-28-2008 09:12 AM
how to decompress gzip file with extension .cif? priya Linux - Software 1 09-05-2003 01:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration