LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 05-16-2016, 11:30 AM   #1
chris_crunch
Member
 
Registered: Jan 2016
Location: Braintree, Essex
Distribution: Ubuntu 14.04
Posts: 107

Rep: Reputation: Disabled
Looping a script on 700+ files?


AT510_67__30_4_16__4_58_12.csv AT510_67__9_5_16__17_20_55.csv
AT510_67__13_5_16__18_52_52.csv AT510_67__16_5_16__12_22_6.csv AT510_67__2_5_16__12_12_39.csv AT510_67__30_4_16__5_58_12.csv AT510_67__9_5_16__18_20_55.csv
AT510_67__13_5_16__19_52_52.csv AT510_67__16_5_16__1_22_6.csv AT510_67__2_5_16__13_12_39.csv AT510_67__30_4_16__6_58_12.csv

Here's a bunch of files I am converting to hdf5s using a python script, running from the command line.
How would I loop this command?
Code:
python converter.py AT510_67__2_5_16__13_12_39.csv 2/5/16/13/12/39.h5
The AT510 is common to all files. I'd really like it if there was a way to name the new files with the date and time.

The format is

Code:
python converter.py csvinputfile h5output file
 
Old 05-16-2016, 11:43 AM   #2
jmgibson1981
Member
 
Registered: Jun 2015
Location: Tucson, AZ USA
Distribution: Debian
Posts: 598

Rep: Reputation: Disabled
Try looking up For Loops
 
Old 05-16-2016, 12:16 PM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,448
Blog Entries: 3

Rep: Reputation: 2711Reputation: 2711Reputation: 2711Reputation: 2711Reputation: 2711Reputation: 2711Reputation: 2711Reputation: 2711Reputation: 2711Reputation: 2711Reputation: 2711
The date program can provide formatted output. If you wrap that in a command substition you can get a name that includes the date and time.

Code:
python converter.py $cvsinputfile $(date +'%F-%H-%M-%S.h5')
 
1 members found this post helpful.
Old 05-16-2016, 11:14 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,809

Rep: Reputation: 3069Reputation: 3069Reputation: 3069Reputation: 3069Reputation: 3069Reputation: 3069Reputation: 3069Reputation: 3069Reputation: 3069Reputation: 3069Reputation: 3069
As suggested, a for loop should be the ticket. A few observations:

1. If running on multiple machines, the call to python may come unstuck if it should point to 3.X or 2.X and will throw errors if the wrong one is used. If you place the interpreter at the head of the file
and make the file executable, you can simply run the script without issue

2. Assuming the path to 'h5' file may need to be created from the file name, you could also do this in the loop
 
  


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
looping in script fw12 Programming 3 11-04-2009 04:48 PM
looping startup script kirukan Linux - Newbie 3 07-10-2009 03:25 PM
Looping in script help needed ZAMO Linux - General 5 08-18-2008 06:17 AM
Looping a script Keentolearn Linux - Newbie 4 01-30-2007 04:54 PM
shell script looping ust Linux - General 2 01-19-2005 05:05 AM

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

All times are GMT -5. The time now is 08:18 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