Sponsored Content
Full Discussion: For Loop queries
Top Forums Shell Programming and Scripting For Loop queries Post 303011702 by weknowd on Monday 22nd of January 2018 03:38:24 PM
Old 01-22-2018
For Loop queries

I have Existing FOR loop in script like below. But the zip should happen for only those years in another file generated dynamically.

Existing FOR LOOP -
Code:
for i in XYZ_*ABC${YEAR_2014}.csv; do
    printf "%s\n" "$i"
    done | zip -@ XYZ_2014.zip  >> $XYZ_2014.log 2>&1 || ERROR_COUNT=$((ERROR_COUNT + 1)) 
    
    
for i in XYZ_*ABC${YEAR_2015}.csv; do
    printf "%s\n" "$i"
    done | zip -@ XYZ_2015.zip  >> $XYZ_2015.log 2>&1 || ERROR_COUNT=$((ERROR_COUNT + 1)) 
    
for i in XYZ_*ABC${YEAR_2016}.csv; do
    printf "%s\n" "$i"
    done | zip -@ XYZ_2016.zip  >> $XYZ_2016.log 2>&1 || ERROR_COUNT=$((ERROR_COUNT + 1))

I have file which has the years for which zip should happen.

dynamic_years.txt
Code:
2014
2015

Updated version should look like below
Code:
for i in XYZ_*ABC${YEAR_2014}.csv; do
    printf "%s\n" "$i"
    done | zip -@ XYZ_2014.zip  >> $XYZ_2014.log 2>&1 || ERROR_COUNT=$((ERROR_COUNT + 1)) 
    
    
for i in XYZ_*ABC${YEAR_2015}.csv; do
    printf "%s\n" "$i"
    done | zip -@ XYZ_2015.zip  >> $XYZ_2015.log 2>&1 || ERROR_COUNT=$((ERROR_COUNT + 1))

It would be helpful if you can let me know how to incorporate the dynamic year change in the FOR loop.

Thanks.

Last edited by Scott; 01-22-2018 at 04:48 PM.. Reason: Please use code tags
 

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Some queries...

Guys need some advice on how to check some of the questions below? i'm running on an open VMS platform... which i am an idiot to... appreciate if anyone can give some hints or source on how to check on.. a script that is running on cron job... but doesn't run as the login user name.. 1. why... (6 Replies)
Discussion started by: 12yearold
6 Replies

2. UNIX for Advanced & Expert Users

Two small queries

Query 1 : How to check if a directory already exists? If doesn't exist then create a new one. Query 2 : I want to put following text using a single echo statement into a log file and also want to retain the formatting of the text. How it can be... (3 Replies)
Discussion started by: skyineyes
3 Replies

3. Shell Programming and Scripting

my queries

hi guys Well, i need to have a report generation script or any script which will show me all the content/information of a file when i run that script. Please help me on this isssue at the earliest.As i am little bit aware of scripting.Thanks in advance! regards ash (4 Replies)
Discussion started by: whizkidash
4 Replies

4. Homework & Coursework Questions

Queries

Any help on like where to get started on this? I'm just confused. 1. The problem statement, all variables and given/known data: Enter text here.Queries to satisfy these two report requests (use your CCI database): Retrieve all rows of active inventory where current on hands is less than... (0 Replies)
Discussion started by: lakers34kb
0 Replies

5. Shell Programming and Scripting

Few queries regarding awk...

One of the command output is as below. -rw-r--r--+ 1 root root 75G Nov 21 16:43 /var/ovs/mount/86BXXX/running_pool/Machine1/System-sda.img -rw-r--r--+ 1 root root 75G Nov 21 16:36 /var/ovs/mount/86BXXX/running_pool/Machine2/System.img -rw-r--r--+ 1 root root 150G Sep 23 19:13... (2 Replies)
Discussion started by: pinga123
2 Replies

6. Programming

Combine 3 queries

can these 3 be combined into 1 query? createtablea1as selecta.tps_Res_nb, b.tkt_prod_cd, b.tkt_prod_typ_nm, b.prod_intrnl_ds, b.tkt_prod_typ_nm AS TKT_ENTL_NM, casewhen b.tkt_prod_nm isnotnullthen b.tkt_prod_nm when b.tkt_prod_nm isnulland b.prod_intrnl_ds isnotnullthen... (1 Reply)
Discussion started by: dwr80
1 Replies

7. UNIX for Advanced & Expert Users

How many DNS queries

Is there any way to see how many queries come into our external DNS server? In looking at DNS providers, most of them base pricing on number of queries per month so I just wanted to see if you had any idea/way of gathering that data? A rough ballpark figure would even work. Our DNS server is... (1 Reply)
Discussion started by: raggmopp
1 Replies

8. IP Networking

RDNS Queries

Hey everyone, I have a question, I've been playing around with tcpdump, and noticed my machine making numerous rdns look ups. They are displayed like: 10.80.80.141.51234 > 10.80.80.1.domain: 9950+ PTR? 223.114.55.65.in-addr.arpa. (44) My question is, if dns works based on numerical... (0 Replies)
Discussion started by: Lost in Cyberia
0 Replies

9. UNIX Desktop Questions & Answers

/etc/motd - queries

If I have /etc/motd, he is file or directory? I saw that some call them folders and files others... Which option is better? I knew that being a director, but many told me not. Thank you! (1 Reply)
Discussion started by: mescu
1 Replies
ZIP_ENTRY_OPEN(3)							 1							 ZIP_ENTRY_OPEN(3)

zip_entry_open - Open a directory entry for reading

SYNOPSIS
bool zip_entry_open (resource $zip, resource $zip_entry, [string $mode]) DESCRIPTION
Opens a directory entry in a zip file for reading. PARAMETERS
o $zip - A valid resource handle returned by zip_open(3). o $zip_entry - A directory entry returned by zip_read(3). o $mode - Any of the modes specified in the documentation of fopen(3). Note Currently, $mode is ignored and is always "rb". This is due to the fact that zip support in PHP is read only access. RETURN VALUES
Returns TRUE on success or FALSE on failure. Note Unlike fopen(3) and other similar functions, the return value of zip_entry_open(3) only indicates the result of the operation and is not needed for reading or closing the directory entry. SEE ALSO
zip_entry_close(3), zip_entry_read(3). PHP Documentation Group ZIP_ENTRY_OPEN(3)
All times are GMT -4. The time now is 07:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy