I have an iCal (Calendar) alarm that is set to go off everyday. It parses a csv that contains emails and a date, then sends an email if it's the appropriate day. The csv is statically coded because I want it to run in the background.
Here is the code for reading the file:
set theLines to paragraphs of (read (open for access file "csv path"))
The problem I'm encountering is that if I modify the csv file (add or remove lines), it seems to read it incorrectly. From what I can tell, prior to modifying it, it works fine.
After I modify it (which I must do periodically), it doesn't read it correctly because it's basing it off of a cached version or something. My only thought is that I'm reading the file incorrectly. Is there a more appropriate way to read a file? I'm new to AppleScript, but not to programming.
You don't need to "open for access". Try this:
set theLines to paragraphs of (read "/Users/Grant/path/to/your/file.txt")
or
set theLines to paragraphs of (do shell script "cat '/Users/Grant/path/to/your/file.txt'")
Related
I have done quite a bit of searching before posting this question so let me outline what I am trying to do.
1.) I do not want to use applications I have to download from a website or created custom commands (please no start Xls2Csv.exe here's a link to a website where you can download the program) I do not want to download a program to do this.
2.) I want to keep it in the batch file if possible - I have tried the vbc/vbs/vb files that is not what I am looking for.
3.) I found this an this is close to what I need but if I can stay within a batch file that would be best: Can a Batch File Tell a program to save a file as? (If so how)
Background
I have a bunch of test records stored in excel sheets within folders. Each test record has autoformatted name so the only real difference between any of the filenames is a serial number, otherwise each file name is formatted the exact same way.
I have written a batch file to search and find the files I need but I am stuck on obtaining a tiny bit of information in a .xls file.
What I am trying to do - I have excel files (.xls) and there is a word in a cell on one of many sheets that I would like to copy into a textfile. However I am unable to use findstr for an excel find because the command searches the file as if you opened it in notepad and the data I need is not present.
I am not concerned of data loss as long as I can get this tiny bit of information to a text file.
Otherwise what I have found to be the best solution is to convert an XLS to a CSV. I have manually done it by opening the file and saving as type .csv that worked.
What hasn't worked is:
example1.xls >> example2.csv
ren example1.xls example3.csv - this will save it as a csv file but still opens with the same formating of the xls file in both excel and notepad.
I was hoping that the was a command to recreate the manual process of opening the file and saving as csv.
If there are any other suggested solutions - maybe a command where I can search for a string within an excel file? That would be the simplest option.
I have a project that involves extracting data from a database into a text file, and then ingesting it into Hadoop. So i want to create a shell script that NiFi can run to automatically to check if a text file is extracted and ingest it, but I need to make sure that the whole data has been extracted first before ingesting it. Meaning I would need to check that the text file has an EOF, how do I do that?
Don't have any code as of yet, I have very little knowledge writing shell scripts.
While creating the file, use a different name. Rename it to the expected name once the extraction is done. Then, the other process can start its work once the file exists.
EOF is not something that actually gets put in the text file - in fact, there isn't really any EOF value. EOF or end-of-file is a condition that occurs when you try to consume input from a source that has none to give.
There is no general marker you can look for in your text files that will tell you whether they are complete. You'll need to make your script indicate when a given chunk of data has been extracted in some other way. There are many possibilities; you could change the name of the file as choroba suggested, or you could create a lock file and remove it once the data extraction is done, or you could have your extraction program write a distinctive sequence of bytes to the file at the end, or so on.
I have a transformation on Pentaho Data Integration where the first thing I do is I use the "CSV Input" to map my flat file.
I've never had a problem with it on windows, but now I'm chaning my server that spoon is going to run to a linux server and now I'm having problems with special characters.
The first thing I noticed was that my tables where being updated because the system was understanding the names as diferent strings to the ones that are at my database.
Checking for the problem, I also noticed that if I go to my "CSV Input" -> Preview, it will show me the preview of my data with the problem above:
Special characters are not showing.
Where it should be:
Diretoria de Suporte à Decisão e Aplicação
I used a command to checked my file charset/codification and it showed:
$ file -bi foo.csv
text/plain; charset=iso-8859-1
If I open foo.csv on vi, it understands the special characters.
Any idea on what could be the problem or what should I try?
I don't have any data files with this encoding, so you'll have to do some experimenting, but there are some steps designed to deal with these issues.
First, the CSV Input step has a field that allows you to select the encoding of the source file. The Text File Input step has both a "Format" (meaning line terminator) and "Encoding" selector under the "Content" tab.
In Transforms, you have the Change file encoding step under the Utility tab. This step is designed to copy many files while changing their encoding; that's why it's in a transform.
In Jobs, there's the Convert file between Windows and Unix step under the File Management tab, but this appears to only deal with line terminators.
Either way it appears if the CSV/Text file input steps don't suit your needs, you'll have to copy the file to a new encoding before reading it in. It will probably be easiest to try handling it with the file input steps first.
Consider I have the following :
An Excel workbook, which generates a .txt file (through a macro).
An executable file (.exe) which can parse this .txt file.
My objective here is to program the following algorithm :
Get the user to enter his data in the worksheets.
Prepare the .txt file according to what the user entered.
Pass the newly created .txt file to the external program (.exe).
Now, the first two steps work perfectly, I can generate the proper .txt file. The problem comes when I need to pass it to the external executable. Here's what's tried and observed :
Calling Shell() with : "C:\path\to\program.exe" "C:\path\to\file.txt" (EDIT : as a single string) ; simple enough, yet this does not work : the external .exe doesn't like being given a path. I have also tried entering the command directly into Windows' Execute utility : same. It seems like giving the program a path to the .txt isn't enough.
Dragging the .txt file onto the program's .exe works! The external executable does its work correctly. Here, it is as if I had passed the "file" to the program, not just its path. As a UNIX user, this sound like quite a non-sense to me (without a notion of stream or pipe), so maybe I'm missing something here...
Now, here's my question. When dragging-n-dropping a file onto an executable, how does Windows "translate" it ? Obviously, it does not translate it to "pass the file's path as the program's first parameter". How can I pass the .txt file to the executable program, without just passing its path like I did with my first Shell() call ?
A few other notes :
I am using Microsoft Office Excel 2010 on Windows 7. I'm already dying from it, thanks for your concern.
This external .exe I'm talking about cannot be modified and recompiled (which would be awesome), that's the tricky thing. I have to use it as it is, whatever happens.
Using Shell() is not a problem, if you give me the proper command/fix. I have also tried calling Run on a VBA.CreateObject("WScript.Shell"), same result.
Now, here's my question. When dragging-n-dropping a file onto an
executable, how does Windows "translate" it ? Obviously, it does not
translate it to "pass the file's path as the program's first
parameter".
It does exactly that. Create a batch file:
#echo off
echo You passed parameter: %1
pause
Save it as test.bat
Browse to it in file explorer, and drag/drop something onto it:
Previous comments:
Looks like you have to send the path and filename as one parameter, e.g.:
Shell("C:\path\to\program.exe C:\path\to\file.txt")
or if the paths have spaces in them, maybe:
Shell("""C:\path\to\program.exe"" ""C:\path\to\file.txt""")
http://social.msdn.microsoft.com/Forums/en-US/a3a3d1a7-5c9a-4c91-ab96-41d367eac2fb/using-shell-function-in-vba-how-do-i-pass-a-parameter?forum=accessdev
I want to build a little application that calculates the critical batch of a batch flow.
As input I need to use a Mainframe dataset. If possible, being dynamic, that is, I can choose the fields that apply at the time.
I've searched the internet about that but found nothing that suited what I wanted to do.
Is there a way to do that?
I have a dataset in a mainframe library and I want to ftp that file to Excel.
Convert the file to CSV on the mainframe (for example, via a REXX exec, a z/OS UNIX shell script, or a Lua4z program),
and then insert that CSV file into Excel via FTP.
You do not need to transfer the CSV file to your PC's file system and then, as a separate step, open it in Excel.
Instead, you define the FTP (or HTTP) URL for the CSV as a data source in Excel. One advantage of this technique is that you can refresh the data from that URL
without having to reapply formatting in Excel.
There are various tutorials on the web for doing this.
In brief:
Create a new blank workbook (I'm using Excel 2010).
Select the first cell in the empty worksheet (this step is unnecessary - the cell is already selected - if you've only just created the workbook).
On the Data tab, click From Text
In the File name text box of the Import Text File dialog, enter the FTP URL of the CSV file. For example:
ftp://zos1//u/me/data.csv
(This assumes that your mainframe is configured to allow FTP using this path.)
The two consecutive slash (/) characters following the host name (zos1) indicate that the path refers to a z/OS UNIX file (/u/me/data.csv).
The CSV file must be in a z/OS UNIX path. The FTP client does not accept MVS-style (dsname) paths such as 'me.csv(data)' (even when URL-encoded; that is, with the single quotes escaped as %27); by contrast, cURL accepts such paths just fine.
The CSV file on the mainframe must be ASCII encoded, not EBCDIC. (Here, I'm using the term ASCII imprecisely: the precise character encoding you want depends on your PC's settings. You probably want Windows-1252.) This is because the FTP client sets the default transfer type to binary.
Enter your user name and password (your z/OS TSO user ID and password).
Wait for the data to load.
Format the cells. For example, set the format of any columns containing date/time values.
On the Data tab, click Connections, select the connection (that Excel created when you specified a URL for the file name), and clear the check box Prompt for file name on refresh.
To refresh the data, replacing the current data with the results of a new FTP request: on the Data tab, click Refresh All. The data is replaced; the cell formatting remains intact.
Converting an EBCDIC-encoded CSV file to ASCII
(Strictly speaking, I mean ISO-8859, not ASCII.)
Suppose you have JCL that generates a CSV file encoded in EBCDIC. You want to make that CSV file available to Excel via FTP as an ASCII-encoded z/OS UNIX (zFS) file.
Replace your existing DD statement for the output CSV file with the following DD statement:
//OUTCSV DD PATH='/u/me/data-ebcdic.csv',
// PATHOPTS=(OWRONLY,OCREAT,OTRUNC),
// PATHDISP=(KEEP,DELETE),
// PATHMODE=(SIRUSR,SIWUSR,SIRGRP),
// FILEDATA=TEXT
Replace the ddname OUTCSV with your ddname, and the zFS file path /u/me/data-ebcdic.csv with the path that you want to use.
Thanks to the FILEDATA=TEXT parameter, the resulting CSV file will have a X'15' byte at the end of each line.
Append the following step to your JCL:
//ICONV EXEC PGM=IKJEFT01
//SYSTSIN DD *
BPXBATCH sh iconv -f IBM-037 -t iso8859-1 +
/u/me/data-ebcdic.csv +
> /u/me/data-ascii.csv
/*
//SYSPRINT DD SYSOUT=*
//SYSTSPRT DD SYSOUT=*
In case you're wondering why I'm calling iconv as a shell command via BPXBATCH, the following:
//ICONV EXEC PGM=EDCICONV
// PARM=('FROMCODE(IBM-037),TOCODE(iso8859-1)')
didn't quite work: it left the X'15' bytes as is, whereas running iconv as a shell command correctly converted them to X'0A'. (z/OS 2.2.)
You've got some good information in the comments, consensus appears to be conversion to CSV (or TSV to avoid commas embedded in your data) is the easiest route. Here is a bit more information, copied from another answer...
I would strongly suggest you get the files into a text format before
transferring them to another box with a different code page. Trying to
deal with mixed text (which must have its code page translated) and
binary (which must not have its code page translated but which likely
must be converted from big endian to little endian) is harder than
doing the conversion up front.
The conversion can likely be done via the SORT utility on the
mainframe. Mainframe SORT utilities tend to have extensive data
manipulation functions. There are other mechanisms you could use
(other utilities, custom code written in the language of your choice,
purchased packages) but this is what we tend to do in these
circumstances.
Once you have your flat files converted such that all data is text,
you can transfer them via FTP or SFTP or FTPS.
...and thanks for coming back and adding more information. Hopefully the people here have provided enough information to help you solve your problem.
XML would be another possible text oriented solution. It would take more effort to create, but you could design your spreadsheet in Excel and save as an XML document, then write a program to generate the xml text using the data from your mainframe dataset. While this would be more difficult to implement than a simple CSV or TSV file, it has the advantage of implementing the spreadsheet formulas and attributes that a CSV file can not do. Another advantage, you can attach the XML document to an SMTP email note and deliver the document in "spreadsheet format" to your client.