Script to create 2 column CSV and zip upon completion

I'm trying to to grab images or PDF's in a folder, add those containing "front" into the 1st column of a CSV, those containing "back" to the 2nd column and then zip/archive it upon completion.  So far I'm using the following script, which add's all PDF/png files to the CSV in a single column.
How do I create column headers and add files containing "front" to the first column and "back" to the second?
Thanks in advance for the help.
do shell script "find ~/Documents/csvConvert/pngFiles \\( -iname '*.png' -or -iname '*.jpg' \\) -exec basename {} \\; | sed -e 's/.pdf$//' -e 's/.jpg$//' -e 's/^.*$/\"&\"/' > $HOME/Documents/csvConvert/Groups/PDFfiles.csv"

I'm not sure how you are running the script e.g. Automator or in an Applescript. Because there are several steps involved I have just done it all in a shell script…
To use it copy & paste into a plain text file (TextWrangler is a decent free code editor with syntax highlighting - it makes life easier).
Save the file as paginator.sh
Make it 'executable' (only need to do this once). In Terminal…
chmod +x paginator.sh
Now you can run it by using…
paginator.sh
Obviously use the full path to the file in those commands (drag & drop the file to get Terminal to autofill it).
This is the script…
#!/bin/sh
# Output file
OUTFILE="${HOME}/list.csv"
# source folder with images
FILES="${HOME}/test/"
# Files for temporary storage of filename lists
FRONTLIST="${HOME}/list-front.txt"
BACKLIST="${HOME}/list-back.txt"
# list front & back into text files
find "${FILES}" \( -iname '*.png' -or -iname '*.jpg' \) -and -iname front\* -exec basename {} \; | sort -n > "${FRONTLIST}"
find "${FILES}" \( -iname '*.png' -or -iname '*.jpg' \) -and -iname back\* -exec basename {} \; | sort -n > "${BACKLIST}"
# Setup CSV with headings
echo "front,back" > "${OUTFILE}"
# Merge 2 list files with a comma
pr -m -t -s\,  "${FRONTLIST}" "${BACKLIST}" >> "${OUTFILE}"
# strip pdf, jpg, png suffixes from the output file
sed -i '' -e 's/\.jpg//g' -e 's/.pdf//g' -e 's/\.png//g' "${OUTFILE}"
# remove temp files
rm "${FRONTLIST}" "${BACKLIST}"
In short it finds the front & back files (sorts then & saves that in two text files).
Then it merges them via 'pr' and removes the suffixes in one pass of the output file. I have removed the last piece of the sed (I'm unsure what it was for).
It saves into  ${HOME}/list.csv Which is the users home folder
There are is room for improvement on this but it creates the csv as desired…
The sort will place front_10.jpg before front_1.jpg (You must use leading zeros on all your files - e.g. file_01.jpg, back_01.png…)
This does not account for nested folders! It will find files at every level! (you can add '-maxdepth 1' to stop find going into nested folders).
The output depends on the file names & if one file is missing the order goes out of sync (you should probably search for the correct 'back_' image & a pair them up correctly with extra logic).
The paths are 'hardcoded' (you can make it accept input so that you can pass the 'files folder' and the 'output file' name into it).
If this is all too complex you could try to re-purpose into an Automator or Applescript, but I think if you are calling repeated 'do shell script' actions it is a sign you could be using the shell itself. It can be wrapped up if you need to make it run like an application - or just give it a '.command' suffix & it should just launch Terminal & run when you double click the file.
Let me know what you think.

Similar Messages

  • PowerShell Script to Create a Contact Card and Enable Email Forwarding

    Exchange 2010
    Can anyone help with creating a powershell script to create a contact card and set email forwarding at the sametime?
    I'm looking to import a list of 200 users via a text or csv file, create the contact card with first name, middle initial if one exists, last name, (no alias) and put the contact card in the following OU "DIS###" in the a.b.c.com domain as well
    as enable forwarding to @mail.com.
    I've been able to create a script to enable mail forwarding but it doesn't help me without a contact card.  I hate to put this upon anyone, but my ps scripting and Exchange knowledge is still in it's infant stage and I need get this done post haste

    Q:Import csv: Does this contain 200 mailboxes name
    A:It contains 200 user logon names.
    For the mail forwarding:
    I currently have a csv file with two columns -- one named displayname and the next call mailaddress.  Under the displayname column I have the users account name (first.mi.last -- middle initial if they have one) and under mailaddress i have @mail.com.                                                                                                           
    script:                                                                                                                                                                    
    Import-CSV C:\setmailforwarding\mailforwarding.csv | foreach-Object{Get-Mailbox $_.displayname | set-Mailbox -forwardingAddress $_.mailaddress}
    The above script should work if the contact card has been created.  Obviously I need to create the card first.
    I don't have a script to set up the contact card as of yet -- I was hoping to get some help on that.
    Q:E-mail forwarding: Is this  from  mailboxes to mail contact, you will be creating
    A:Not really sure what you are asking.  I'm looking to create the contact card with a csv or txt file for first name, middle initial if one exists, last name, (no alias) and put the contact card in the following OU "DIS###" in the a.b.c.com domain as
    well as enable forwarding to @mail.com.  The users current email is @mail.1234.com and we will be migrating our mailboxes to another organization that uses @mail.com.  I will need to set forwarding in the interim until the migration is complete.
    Hope this helps.

  • Creating an XLS file and Zip it

    Hi All,
    we have a requirement where in we have to create an XLS file from internal table. This xls file then has to be zipped and mailed.
    If anyone knows how to create an xls file and zip it in WebDynpro, without using OPEN, CLOSE DATA SET etc, Please let us know. It will be of great help.
    Thanks,
    Anand

    >2) Convert the STRING format to XSTRING format by using the FM SCMS_STRING_TO_XSTRING.
    Actually you should use CL_BCS_CONVERT=>STRING_TO_XSTRING now.
    >3) Use the method COMPRESS_BINARY of class CL_ABAP_GZIP to compress the XSTRING file.
    You probably want to use CL_ABAP_ZIP instead of CL_ABAP_GZIP.  CL_ABAP_GZIP only does compression, which is fine for storing a single packet of data in the database.  However CL_ABAP_ZIP is better suited for mult-part zip (multiple inner files).
    >4) Use the method SEND_WEB_MAIL of class CL_HRRCF_SERVICES_MAIL to mail across the zipped contents.
    This seems to be an HR specific class. Better to use the cross application, NetWeaver provided functionality for sending mail - CL_BCS.

  • Script Add bulk user with CSV, and set expiration date

    After importing the AD module, the line:
    Set-ADAccountExpiration -identity JohnDoe -timespan "365"
    Works just fine, but how would you automate this with a script that would read a csv-file. The -identity cmd dosen't seem to like my $SAM setup. Perhaps it's a better way to get-aduser and pipe it to set-accountexpiration. Is there a swift way to add the
    expire date to the user I just created with my CSV-file?
    Thanks!

    Thank You!
    You're very welcome.
    -AccountExpirationDate parameter of New-ADUser only seem to work with -DateTime, a specific date, while -TimeSpan is optimal for this solution.
    You can use Get-Date's AddDays method to generate a datetime object for use in this situation, see the code I'm posting below for an example.
    Now on to the next challange to warn me when they reach "32" days before expiration. Was thinking of running a Task Scheduled bath file that could collect number of days left and report it if below the mentioned days.
    Here's one method you can use for finding these users:
    $cutoffDate = (Get-Date).AddDays(32)
    Get-ADUser -Filter * -SearchBase 'OU=Users - TEST,DC=domain,DC=com' -Properties AccountExpirationDate |
    Where { $_.AccountExpirationDate -and $_.AccountExpirationDate -lt $cutoffDate }
    Just so you're aware, we generally try to keep threads to a single question.
    Don't retire TechNet! -
    (Don't give up yet - 13,085+ strong and growing)

  • A script to create a new folder and place selected items into it?

    I'd like to select a few items and have either an Apple script / contextual menu automatically create a new folder and place the selected items inside it.
    I have many, many to do—which is why I wanted to know if there is a script or automator or contextual menu thing available. Or if not, how can I create one?
    Can that be done? Thank you!

    Thank you for your help. Now I just want to expand on this a bit. To use the Applescript you have supplied me, how do I tell it to name the folder other than by date, and where to put it?
    Let me say, preferably, is it possible to make an action like this right-clickable? Instead of having to pick a script. Anything that slows this process down means I might as well do it all by hand. What I'd really love to do is this:
    Select a number of items. Right click to an action saying "create a new folder and put this items in it. Name the folder with the first item's name". Very simple and quick.
    Could this be accomplished? Through Automator? or something that can appear in the contextual menu? Folder actions?
    I'm just getting started with using these tools.

  • Creating a column link and using a date/time field as one of the Items

    I have created an Interactive Report and set up a column link to another page. One of the Items in the column link is a Date field. When I click on the link I receive 'ORA-01403: no data found' for the linked page. In the Session attributes only DD-MON-YYYY HH24 passed and MI (minutes) was truncated... causing the error. I have created the same link on a Non-Interactive Report, DD-MON-YYYY HH24MI gets passed and the link works. Anyone have any clues on why the full date/time format is not being passed?
    The Item on the linked page has been set to Date Picker (DD-MON-YYYY HH24MI)
    Application Date Format is DD-MON-YYYY HH24:MI

    Hi,
    As David says colon is separator in URL for parameters.
    This is same kind of post about problem about comma. Values are separated by comma in URL. It might help you
    value truncation while printing page field in HTML
    Regards,
    Jari

  • SSIS - Script Task creates a DTS var and using Foreach loop, Execute SQL needs to INSERT into table from this DTS var.

    I have a script task written in C# that creates an array of strings "arrayFields" after parsing a text file. It saves the array of strings in a DTS variable.
    Each row in array represents a row is comma separated and is a row that must be inserted into a table. For example,
    X and Z are fields in the table
    X1, X2,....Xn
    Z1,Z2,...Zn
    I am using a Foreach Loop  to grab each row and then  Execute SQL Task to take each row from the array and insert each field per row in a table,
    The SQL is something like,
    INSERT dbo.table values(field1, field2,...fieldn) arrayFields?
    What should this this INSERT look like?

    I guess you implemented
    Shredding a Recordset
    Based on what I understood (correct me if I am wrong) you have difficulties mapping the input parameters, if so here is the guide
    http://www.sqlis.com/sqlis/post/The-Execute-SQL-Task.aspx
    In short it might look like
    INSERT dbo.table  (ColumnA, ColumnB,...) VALUES (?,?...)
    The syntax for the T-SQL INSERT is http://technet.microsoft.com/en-us/library/dd776381%28v=sql.105%29.aspx
    Arthur
    MyBlog
    Twitter

  • Media Mania and Thoughts upon completing a 6 year project...

    I am wrapping up the first of 2 documentary films that I have been working on for some time now. Just finishing the renders of the 2 hour show with the Nattress film look filters, shot on DVCam. I think it looks nice. Lo-o--ong render times though in 10 bit!
    Editing the shows on FCP was a breeze--a complete pleasure besides a couple of little bumps with the Aja IO and etc.
    The real problem was in the finishing. FCP (HD at least)is not ready for the big time.
    I come from an Avid background. I am used to doing a Decompose and bing, bang boom--hi rez recapture, no problemo. The Media Manager in FCP is horrible. It is not "Pro" or anywhere near it. I cannot count the hours that it took me to recapture and reconstruct clips that had messed up time code, speed or both after shrinking the project (and previously copting it to a new drive) with Media Manager. Absolute frustration.
    I spent an extra $5500 getting a setup (deck, scopes and Aja IO) so I could finish on my system instead of going elsewhere...Absolute frustration.
    I have another 2 hour show to finish as soon as I am done with this one...
    Does anyone have any suggestions on how to save my sanity with this brain numbing process? Is 5.0 better with this stuff? Am I doomed to spend an extra week on my online cleaning up FCP mistakes?
    As always thanks in advance and thanks for all of your help over the last six months or so.

    "We know it can be done. We just don't know how. "
    Does anybody know how? It should work for everybody, not the VERY few people who it actually does work for.
    WHY NOT motion control clips? I don't get it...
    Yeah, I tried the a work around described by someone--put regular "no speed change" versions of the clips at the end of the timeline and recapture--the motion control slips were still messed up. Why should I have to go back and redo work I did previously--i.e. slow the clips down again and cut them back into the show EVEN if it did work?
    Then, you go in and manually readjust the screwed up motion and change it to back to Constant from Variable and remove the freeze frame or backwards playback of the video that FCP added, save the change and then go back to the clip later on and FCP has f'ed it up again and put some other new speed thing on it.
    Anyway, I am as big a proponent of FCP as anyone but this is NOT a ready for prime time work flow. It just isn't. You have to be able to rely on your gear to get stuff done. I am glad I was not on a deadline or I would have been downright screwed.
    It's bad enough to have all of the tape changes involved with capturing one timeline at a time (seperate projects are necessary or Out of Memory comes into play-) without all of the other problems.
    P.S., I am not just venting, I what some real solutions from anyone who really knows how.
    As always, thanks.

  • Column based on Approval Workflow completion date

    Would anyone know of a way to create a column that will display the completion date of an approval workflow than ran on a specific file in another library?
    Thank You

    It could be a simple single line of column
    The workflow on other file must update this column, then only it can hold data
    In SharePoint designer workflow, it can be done easily with "Create a list item" action.
    You can refer this video - http://www.lynda.com/SharePoint-tutorials/Creating-new-list-item/144025/161251-4.html
    Let me know if you need more help.
    Please 'propose as answer' if it helped you, also 'vote helpful' if you like this reply.

  • Need to import csv and manipulate one column

    I have a monthly report output by an FTP program into CSV format. The CSV file has headers and 3 columns:
    1) a group name
    2) the number of transfers that group made
    3) the total size of all their transfers (in bytes)
    Example (with headers and 6 rows of data for 7 rows total):
    "monthly transfers","sum of monthly transfers","sum of file size"
    "group1 (Prod to Dev)","26","11556381672"
    "group2 (Prod to Dev)","5","348197396"
    "group3 (Prod to Dev)","14","1272913379"
    "group1 (Dev to Prod)","0","0"
    "group2 (Dev to Prod)","1976","2036311426"
    "group3 (Dev to Prod)","1","131"
    I have been asked to write a script that will convert the bytes to megabytes and then sort based on group name and export the new data so auditors (non-technical people) can review it.
    I've worked with Excel a bunch in Powershell (I.E. opening a com object and writing directly to a cell) and I'd prefer to do it that way, but the server this script needs to run on doesn't have MS Office installed and can't have anything else installed on
    it, so I'm trying to learn about import-csv and such. I've come up with this:
    $file = "C:\ftp\ftp_report.csv"
    $csv = import-csv $file
    $csv | sort "monthly transfers"
    The part I'm stuck on is converting that third column from bytes to megabytes. I know that in Powershell I can do "X / 1mb" to convert a number from bytes to megabytes, but I'm not sure of how best to do this in a specific column of a CSV file.
    Should I create a hash table? Should I count the number of rows and then do a "foreach" on
    $csv[0].'sum of file size' / 1mb
    Am I overthinking this and there's a really easy way to manipulate all values in a column?
    Thank you in advance.
    [email protected]

    Probably like this, right at the parameter:
    ("{0:N2}" -f ($row.'sum of file size' / 1mb))
    There's no place like 127.0.0.1

  • Generating CSV file with column names and data from the MySQL with JAVA

    Hi all,
    Give small example on ...
    How can I add column names and data to a CSV from from MySQL.
    like
    example
    sequence_no, time_date, col_name, col_name
    123, 27-apr-2004, data, data
    234, 27-apr-2004, data, data
    Pls give small exeample on this.
    Thanks & Regards
    Rama Krishna

    Hello Rama Krishna,
    Check this code:
    Example below exports data from MySQL Select query to CSV file.
    testtable structure
    CREATE TABLE testtable
    (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    text varchar(45) NOT NULL,
    price integer not null);
    Application takes path of output file as an argument.
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.Statement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    public class automateExport {
        public static void main(String[] args) {
            DBase db = new DBase();
            Connection conn = db.connect(
                    "jdbc:mysql://localhost:3306/test","root","caspian");
            if (args.length != 1) {
                System.out.println(
                        "Usage: java automateExport [outputfile path] ");
                return;
            db.exportData(conn,args[0]);
    class DBase {
        public DBase() {
        public Connection connect(String db_connect_str,
                String db_userid, String db_password) {
            Connection conn;
            try {
                Class.forName("com.mysql.jdbc.Driver").newInstance();
                conn = DriverManager.getConnection(db_connect_str,
                        db_userid, db_password);
            } catch(Exception e) {
                e.printStackTrace();
                conn = null;
            return conn;
        public void exportData(Connection conn,String filename) {
            Statement stmt;
            String query;
            try {
                stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                        ResultSet.CONCUR_UPDATABLE);
                //For comma separated file
                query = "SELECT id,text,price into OUTFILE  '"+filename+
                        "' FIELDS TERMINATED BY ',' FROM testtable t";
                stmt.executeQuery(query);
            } catch(Exception e) {
                e.printStackTrace();
                stmt = null;
    Greetings,
    Praveen Gudapati

  • How to create power shell script to upload all termset csv files into the SharePoint2013 local taxonomy ?

    Hi Everyone,
    I want to create a powershell script file
    1) Check a directory and upload all termset csv files into the SharePoint local taxonomy.
    2) Input paramaters - directory that containss termset csv files, Local Termstore to import to,
    3) Prior to updating get a backup of the existing termstore (for rollback/recovery purposes)
    4) Parameters should be passed in via XML file.
    Please let me know how to do it.
    Regards,
    Srinivas

    Hi,
    Please check this link
    http://termsetimporter.codeplex.com/
    Please remember to click 'Mark as Answer' on the answer if it helps you

  • Script to create grants and synonyms for objects in database

    Hello,
    We are building a patch to be applied to the production environment. I want to create a script/sql query that builds a list of grants and synonyms for all the objects created after august 09.
    for ex:
    create or replace synonym abc for schema_name.abc;
    Grant execute on abc to user_xyz;
    How can I use Oracle's data dictionary to do this?
    thankz

    Hi,
    You'll probably want to use these views:
    user_objects - includes created (DATE) column.
    user_synonyms
    user_tab_privs - not just tables (e.g., includes EXECUTE privileges on functions).
    Data dictionary views beginning with 'user_' cover objects owned by the current user only.
    Almost all of the data dictionary views (and all of the three mentioned above) also have 'all_' and 'dba_' versions.
    For example:
    all_objects inculdes everything in user_objects, plus objects in other schemas on which the current user has privileges.
    dba_objects include every object in the database. (Not everyone is allowed to see the dba_ views.)
    Here's one of many possible ways to use these views:
    SELECT     'GRANT '
    ||     privilege
    ||     ' ON "'
    ||     table_name
    ||     '" TO '
    ||     grantee
    ||     CASE
              WHEN  grantable = 'YES'
              THEN  ' WITH GRANT OPTION;'
              ELSE  ';'
         END
    FROM     user_tab_privs
    WHERE     table_name  IN (          -- Only interested in objects created after August 9
                     SELECT  object_name
                     FROM    all_objects
                     WHERE   created >= TO_DATE ( '10-Aug-2009'
                                                           , 'DD-Mon-YYYY'
    ;

  • Script to list Hyper-v CSV disks and their LUNs

    Hi all
    I am getting to grips with powershell now but one thing i am struggling to do is create a script that will query CSV's volumes and show their SAN volume LUNs.
    Have searched frantically and pieced together something, which uses two WMI queries to gather the information and then use the signature to match them up. However, some CSVs do not come back with a signature. 
    Now surely to match a CSV with the corresponding physical disk and thus its LUN should be easy. Looks like lots of people have tried to crack this with WMI queries and even using diskpart. But their has to be an easy way. We are running 2012 Hyper-v
    and 2012 R2 clusters. So a solution for either platform would be good.
    Thanks

    Hi Chris Ryan,
    To get the CSV and their LUNs , you can start the
    Failover Clusters Cmdlets  in powershell, please check the script below:
    Getting More Information About You Cluster LUN’s
    Best Regards,
    Anna

  • I have a request from a customer to run a script to create multiple Usernames and Passwords on ACS5.3 appliance.

    I have a request from a cutomer to run a script to create multiple username and password on ACS5.3 Appliance. Does anyone has any suggestion on how to go about this?

    Have you tried using the import option on the ACS? You can put all your accounts in a csv file and upload it into the ASA.
    http://www.cisco.com/en/US/docs/net_mgmt/cisco_secure_access_control_system/5.3/user/guide/users_id_stores.html#wp1132152
    If that doesnt work you can use the REST Web Services in ACS also:
    http://www.cisco.com/en/US/docs/net_mgmt/cisco_secure_access_control_system/5.3/sdk/rest.html
    Thanks,
    Tarik Admani
    *Please rate helpful posts*

Maybe you are looking for

  • Can not open PDF Files-have windows 7 & downloaded Adobe 9.2

    Can not open up any PDF files.  I have a new computer with windows 7.  Have dowloaded 9.2 adobe reader as well as air.  It comes up as File Conversion with options of select the encoding that makes your document readable.  Nothing I choose works & th

  • Transfer recorded tv to N95

    Hi, I've been having some problems transcoding recorded tv ( files recorded using media center in .dvr-ms ) to watch my N95, even after reading these discussions and downloading 'Super'. Super works fine for encoding mpegs and avi's etc. but I can't

  • Transfer music from an iPod to another

    Hi guys i boght today my second iPod, a 5g 30 gb,my first was a Nano 2gb..i bought the new one 'cause a week ago, keeping my nano on my pocket the screen has gone KO...(@#@#@#@#@#) my question is...is it possible to transfer file from my old Nano to

  • How to stop and Start ASM in 11gR2

    Hi, Any one please let me know the complete process of how to stop and start the ASM instance in 11.2.0.1 oracle. Thanks. Ali

  • Time Machine size discrepancy / backup fail

    Hi! For a few weeks now my Time Machine backups have ceased to work, with an error that they are too big for the drive. While I only have a 500GB drive, my total size of the backup has always been well within that (thanks to the exclusions I have set