LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 12-23-2016, 04:06 AM   #1
ROOTS_S
LQ Newbie
 
Registered: Dec 2016
Posts: 1

Rep: Reputation: Disabled
How to zip csv files having specific pattern in a directory using UNIX shell script?


I have files in a Linux directory . Some of the file is listed below

Quote:
-rw-rw-r--. 1 roots roots 0 Dec 23 02:17 zzz_123_00000_A_1.csv
-rw-rw-r--. 1 roots roots 0 Dec 23 02:18 zzz_121_00000_A_2.csv
-rw-rw-r--. 1 roots roots 0 Dec 23 02:18 zzz_124_00000_A_3.csv
drwxrwxr-x. 2 roots roots 6 Dec 23 02:18 zzz
-rw-rw-r--. 1 roots roots 0 Dec 23 02:54 yyy_123_343434_A_1.csv
-rw-rw-r--. 1 roots roots 0 Dec 23 02:55 yyy_123_343434_A_1.xml
-rw-rw-r--. 1 roots roots 0 Dec 23 02:55 yyy_1254_343434_A_1.csv
-rw-rw-r--. 1 roots roots 0 Dec 23 02:55 yyy_1254_343434_A_1.txt
drwxrwxr-x. 2 roots roots 6 Dec 23 02:56 yyy
In my directory other file formats also there with same name. And my direcotry might have sub directory also. I should not consider other files and sub directories for zip process.
Once zip is done,I have to move this csv files into archive directory. I have to write unix script.

Expected Output:

Quote:
zzz_timestamp.zip
should have
Quote:
zzz_123_00000_A_1.csv,zzz_121_00000_A_2.csv and zzz_124_00000_A_3.csv
Quote:
yyy_timestamp.zip
should have
Quote:
yyy_123_343434_A_1.csv,yyy_1254_343434_A_1.csv
Please let me know how to implement this task.
 
Old 12-23-2016, 04:27 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 20,836

Rep: Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008
Quote:
Originally Posted by ROOTS_S View Post
I have to write unix script.
Indeed you do. Not us.
What have you tried ?.
 
Old 12-23-2016, 04:29 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 6,901
Blog Entries: 3

Rep: Reputation: 3584Reputation: 3584Reputation: 3584Reputation: 3584Reputation: 3584Reputation: 3584Reputation: 3584Reputation: 3584Reputation: 3584Reputation: 3584Reputation: 3584
Work out each step manually first.

I would start with find and work out a formula that will show you the list of files to be archived. Then pass that to tar or "zip"

Once you have that, copy the line and modify the copy so that it moves the files to the directory of your choice.
 
Old 12-23-2016, 06:36 AM   #4
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Show us your work.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
searching for files having pattern with shell script ramsavi Programming 1 05-15-2013 02:57 AM
Shell Script for Identifying the file and zip all files, move the files to Target Dir gvenkat Linux - Newbie 3 05-07-2011 10:53 AM
[SOLVED] Removing a line from file which is having specific pattern using shell script emcykm Linux - Newbie 5 03-21-2011 05:49 AM
Shell Script & CSV files Inbhir Pheofharain Programming 17 05-18-2009 01:24 PM
Select the files of a directory that match a specific pattern jianelisj Linux - Newbie 2 03-17-2008 12:25 PM

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

All times are GMT -5. The time now is 06:46 PM.

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