How to zip or rm the multi part named files?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to zip or rm the multi part named files?
# 1  
Old 09-24-2013
How to zip or rm the multi part named files?

Hello There,

There are more than 1000 files in my log folder and i want to zip it to relase the space. But my method throwing
syntax error due to the multi part file name, how to overcome in this ?

Code:
ls -lart | grep "MDB_Kernel11.1_gwlog_SUN 22_09_2013" | awk '{print $9,$10,$11,$12}' | head -10
MDB_Kernel11.1_gwlog_SUN 22_09_2013 09_21_34 PM_45563.log
MDB_Kernel11.1_gwlog_SUN 22_09_2013 09_21_34 PM_40460.log
MDB_Kernel11.1_gwlog_SUN 22_09_2013 09_21_34 PM_39326.log
MDB_Kernel11.1_gwlog_SUN 22_09_2013 09_21_34 PM_37854.log
MDB_Kernel11.1_gwlog_SUN 22_09_2013 09_21_34 PM_36535.log
MDB_Kernel11.1_gwlog_SUN 22_09_2013 09_21_34 PM_36162.log
MDB_Kernel11.1_gwlog_SUN 22_09_2013 09_21_34 PM_35668.log
MDB_Kernel11.1_gwlog_SUN 22_09_2013 09_21_34 PM_35190.log
MDB_Kernel11.1_gwlog_SUN 22_09_2013 09_21_34 PM_34760.log
MDB_Kernel11.1_gwlog_SUN 22_09_2013 09_21_34 PM_33756.log
for i in 'ls -lart | grep "MDB_Kernel11.1_gwlog_SUN 22_09_2013" | awk '{print $9,$10,$11,$12}' | head -10'
do
gzip $i
done

From above the files having space in between their name, so zip or remove commands throwing error. Please assist.


Gowtham.G
# 2  
Old 09-24-2013
Code:
...
gzip "$i"
...

--ahamed
# 3  
Old 09-24-2013
Code:
 
for i in 'ls -lart | grep "MDB_Kernel11.1_gwlog_SUN 22_09_2013" | awk '{print $9,$10,$11,$12}' | head -10'

Those quotes should be ` instead of '
# 4  
Old 09-24-2013
Code:
for i in MDB_Kernel11.1_gwlog_SUN\ 22_09_2013*
do
  gzip "$i"
done

--ahamed
# 5  
Old 09-24-2013
awk '{print $9,$10,$11,$12}'
This is extracting PART of the file name, you will need the full file name to perform zip or rm commands.

Code:
for i in 'ls -lart | grep "MDB_Kernel11.1_gwlog_SUN 22_09_2013"  | head -10'
do
    rm "$I"
done

# 6  
Old 09-25-2013
Thanks everyone for the reply. But am still getting the same error.


Code:
for i in `ls -lart | grep "MDB_Kernel11.1_gwlog_TUE 24_09_2013 *" | head -10 | awk '{print $9,$10,$11,$12}' `
> do
> rm "$i"
> done
rm: MDB_Kernel11.1_gwlog_TUE: A file or directory in the path name does not exist.
rm: 24_09_2013: A file or directory in the path name does not exist.
rm: 03_37_06: A file or directory in the path name does not exist.


Please help me.
# 7  
Old 09-25-2013
Faced this issue once. Do this for your gzip:

gzip '"$i"'

(Single quotes,double quotes, $i, double quotes,single quotes)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (1 Reply)
Discussion started by: b.saipriyanka
1 Replies

2. UNIX for Beginners Questions & Answers

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (2 Replies)
Discussion started by: b.saipriyanka
2 Replies

3. Shell Programming and Scripting

Unzip all the files with subdirectories present and append a part of string from the main .zip files

Hi frnds, My requirement is I have a zip file with name say eg: test_ABC_UH_ccde2a_awdeaea_20150422.zip within that there are subdirectories on each directory we again have .zip files and in that we have files like mama20150422.gz and so on. Iam in need of a bash script so that it unzips... (0 Replies)
Discussion started by: Ravi Kishore
0 Replies

4. Shell Programming and Scripting

Zip Multiple files to One .zip file in AIX system

Hi I have a requirement in unix shell where I need to zip multiple files on server to one single .zip file. I dont see zip command in AIX and gzip command not doing completely what I want. One I do .zip file, I should be able to unzip in my local Computer. Here is example what I want... (9 Replies)
Discussion started by: RAMA PULI
9 Replies

5. Shell Programming and Scripting

Working with files that are named with a timestamp

So I have a script that runs an ls on a given directory and looks for files with a timestamp that has the current hour in it and then does work with the files that it discovers DATE=`date +'%y%m%d%H'` HOSTIS=`hostname` #EMAIL NOTIFICATION ALS EMAIL=address@server.com # if ; then ... (5 Replies)
Discussion started by: os2mac
5 Replies

6. AIX

ZIP multiple files and also specify size of zip file

I have to zip many pdf files and the size of zip file must not exceed 200 MB. When size is more than 200 MB then multiple zip files needs to be created. How we can achieve this in UNIX? I have tried ZIP utility but it takes a lot of time when we add individual pdfs by looping through a... (1 Reply)
Discussion started by: tom007
1 Replies

7. Shell Programming and Scripting

cat certain files in directories to files named after the dir?

Hi all, I have a directory with many subdirectories each named like so: KOG0001, KOG0002, ...KOG9999. Each of these subdirectories contain a variable number two kinds of files (nuc and prot) named like so: Capitella_sp_nuc_hits.fasta (nuc) and Capitella_sp_prot_hits.fasta (prot). The... (2 Replies)
Discussion started by: kmkocot
2 Replies

8. UNIX for Dummies Questions & Answers

multi part compressed files

Hi there, not sure if I am in the right place but here is my question. I have a file that is over 100mb and my host does not allow FTP of files above 100mb so I thought I would use a compression utility to compress it into smaller parts say 10mb each, upload them and then re-assemble them on... (7 Replies)
Discussion started by: gffb
7 Replies

9. UNIX for Dummies Questions & Answers

unzip .zip file and list the files included in the .zip archive

Hello, I am trying to return the name of the resulting file from a .zip archive file using unix unzip command. unzip c07212007.cef7081.zip Archive: c07212007.cef7081.zip SecureZIP for z/OS by PKWARE inflating: CEP/CEM7080/PPVBILL/PASS/G0063V00 I used the following command to unzip in... (5 Replies)
Discussion started by: oracledev
5 Replies

10. UNIX for Dummies Questions & Answers

Best practice for bulk multi-part mail

Hi, I am currently building a PHP/MySQL database that handles our offices newsletters. Now everything works great in the alpha with only a few names in the list, but I anticipate that once we fill it up (around 10,000) that this will not work from the PHP. I already have the script echo the... (0 Replies)
Discussion started by: begin23
0 Replies
Login or Register to Ask a Question