Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bobbybill

macrumors newbie
Original poster
Sep 15, 2012
9
0
UPDATE: I've figured out how to run the .rb. But I'm hung up on an error code when I'm in the terminal:
"There was an error reading SKU.csv: No such file or directory - SKU.csv
Exiting..."



Hello:

Check out this link to an old post on MacRumors--

https://forums.macrumors.com/threads/782851/


I want to do the same thing but have not been able to figure out the steps to take--according to the original responder--or whether the new Lion OS has any significant differences compared to the original post.

Thanks for your help!
 
Last edited:
The "old post" you've linked to is a member page, not a post, or even a thread. It's a bit much to search that member's entire post history to find something that might be CSV-related.
 
Post the exact commands you used in Terminal (copy and paste them), along with the error messages.

If you used double-click on the .rb, copy and paste the complete text from the Terminal window.


The URL with the .rb file is here:
http://www.roguepenguin.net/PFID2SKU/

There is a downloadable "SKU.csv" file also available there. Did you download that file, too? Where did you put it?


I'm trying to pin down exactly what you did. The command-line must be accurate and specific. Since the original thread didn't include any examples of the command-line, it tells you to read the start of the .rb file for information on how to customize the .rb file. Did you do that? Exactly what did you do as a result? The .rb file clearly needs to be customized, so exactly how did you customize it?

We can't see your screen, so you have to tell us exactly what you did, for each customization and every command-line you entered. For example, you haven't told us whether you typed in a command-line, or whether you used double-click in Finder.
 
What I tried...

Background: To test whether it would work on my own data..I used the data provided in the old post. I have a folder named 'namechangetest' with 2 subfolders: 'PFIDimages' & 'SKUimages', and 2 documents (PFID2SKU.rb & SKU.csv) Within the 'PFIDfolder' are 5 images (PFIDimages)that correspond to values in 'A:A' column.

First I tried double-clicking the .rb file. That opened the file in xcode by default. After that I tried to do this in the terminal:

Code:
 Nicks-MacBook-Pro:~ nickburggraf$ ruby ~/desktop/Namechangetest/PFID2SKU.rb

which gave me:

Code:
 There was an error reading SKU2.csv: No such file or directory - SKU2.csv
Exiting...

Then I tried copying and pasting into the terminal--all the lines in the code--see attachment.
 

Attachments

  • terminal_output_testA.txt
    12.7 KB · Views: 224
Last edited by a moderator:
Try this: copy and paste the following into a Terminal window:
Code:
cd ~/Desktop/namechangetest
ruby ./PFID2SKU.rb
Describe what happens.
 
I tested the script. Made some images. Perhaps it makes things clearer.
 

Attachments

  • Screen shot 2012-09-16 at 00.05.28.png
    Screen shot 2012-09-16 at 00.05.28.png
    58.3 KB · Views: 147
  • Screen shot 2012-09-16 at 00.06.33.png
    Screen shot 2012-09-16 at 00.06.33.png
    173.1 KB · Views: 158
Last edited:
Attempted to copy-paste, as from CHOWN

I received this result:

Code:
Last login: Sat Sep 15 17:59:07 on ttys000
Nicks-MacBook-Pro:~ nickburggraf$ cd ~/Desktop/Namechangetest
Nicks-MacBook-Pro:Namechangetest nickburggraf$ ruby ./PFID2SKU.rb
009-07-0414 Weber Smokey Joe.jpg,030-04-1821' does not appear to be a valid mapping
Exiting...
 
I received this result:

Code:
Last login: Sat Sep 15 17:59:07 on ttys000
Nicks-MacBook-Pro:~ nickburggraf$ cd ~/Desktop/Namechangetest
Nicks-MacBook-Pro:Namechangetest nickburggraf$ ruby ./PFID2SKU.rb
009-07-0414 Weber Smokey Joe.jpg,030-04-1821' does not appear to be a valid mapping
Exiting...

Refer to post #5 in the original thread.

If that doesn't answer your question, then you need to post the actual file you're using as your "SKU.csv".
 
Don't know if this is the result you expected as your SKU has no extension.
 

Attachments

  • Screen shot 2012-09-16 at 02.15.25.png
    Screen shot 2012-09-16 at 02.15.25.png
    19.4 KB · Views: 132
  • Screen shot 2012-09-16 at 02.16.12.png
    Screen shot 2012-09-16 at 02.16.12.png
    103 KB · Views: 135
Please stand by...

I am going to post everything that I have when I get home--just about to leave work. 30 min.

Thank you for all your help..Looking forward to figuring it out (or should I say, having one of you figure it out). Thanks.
 
Don't know if this is the result you expected as your SKU has no extension.

There's only one error message in the Ruby script that says "invalid mapping" (hilited in red):
Code:
      if tokens.size == 2                             #the split line should have 2 substrings/tokens
        pfid_name = tokens[0].strip                   #remove any extra whitespace on first token
        sku_name = tokens[1].strip                    #remove any extra whitespace on second token
        if mapping.has_key?(pfid_name)                #make sure we have not already encountered this PFID name 
          raise "'#{pfid_name}' already exists (this is a duplicate)"     #throw an error if we have
        else
          mapping[pfid_name] = sku_name               #map the PFID to the SKU name
        end
      else                                            #if there are not two substrings/tokens, raise an error
        [COLOR="Red"]raise "The line '#{line}' does not appear to be a valid mapping"[/COLOR]
      end
This code is part of the initial parsing, so AFAICT it's just splitting strings and looking for 2 parts. It's not actually looking for files yet.

I note that the words "The line" are missing from the posted error message, so I suspect some error in the data. For example, a lone CR might cause the line-parsing code to malfunction (I don't know how Ruby parses lines), effectively treating two lines separated by a single CR as a single line that looks like "id1,sku1 CR id2,sku2". This would fit both the message output and the code logic, but it's just a guess; I'll wait to get the actual data file.
 
The Data

Here is everything I have--that I am supposed to have?

Contained in the .zip:
SKU.csv (4 entries)
PFID2SKU.rb
pfidimages folder w/ 4 images
skuimages--empty
 

Attachments

  • Namechangetest.zip
    2.5 MB · Views: 112
Your csv file is malformed as chown33 suspected.
 

Attachments

  • Screen shot 2012-09-16 at 03.42.31.png
    Screen shot 2012-09-16 at 03.42.31.png
    50.6 KB · Views: 144
  • Screen shot 2012-09-16 at 03.53.57.png
    Screen shot 2012-09-16 at 03.53.57.png
    54.2 KB · Views: 150
  • SKU.zip
    802 bytes · Views: 83
Last edited:
Malformed?!

Oh no! Do you know the way to form it correctly? I attempted a new .csv from scratch, but yielded the same result.
 
Oh no! Do you know the way to form it correctly? I attempted a new .csv from scratch, but yielded the same result.

What program are you using to produce the .csv file? It may have an option to control line-endings. The kind needed here is often called "Unix style" line-endings.

If you can't control the line-ending style, you can edit the .csv file after it's been produced, and change the line-endings. A simple way to do that is with TextWrangler. After installing it (drag-and-drop) and launching it (skip registration for now, also skip installing command-line utilities), open your .csv file.

Without changing any preferences, look at the bottom of the window. There should be a few assorted popups, and one of them should say something like "Classic Mac (CR)". Click that and choose "Unix (LF)". Save. The newly-saved file should now have Unix-style line-endings, so run the command-line as previously shown, and describe the results.

There are other ways to convert line-endings, including with a command-line, but TextWrangler is a useful tool so you might as well have it handy. There are almost certainly other text editors that can convert line-endings, but TextWrangler is definitely free (I don't know about others), easy to install (not always the case), and the line-ending conversion is right there after a default install.


p.s. We programmers often use "malformed" only in the sense "not what was expected" or "not in the conventional way". It's almost never in the sense "something diabolical or horrific has happened" (that would be "grossly malformed"). Since most programs that produce text on Mac OS X do so with Unix-style line-endings, "malformed" only means "not using the conventional line-endings".

EDIT

Duh, TextWrangler is also free on the Mac App Store.
http://itunes.apple.com/us/app/textwrangler/id404010395?mt=12
 
Last edited:
Sorry, I didn't reply earlier but I seem to have dozed off after my last post(5 o'clock in the morning here). Thanks chown33 for the TextWrangler guidance and the p.s. ;)

@bobbybill

I guess the command line chown33 mentioned would be :

Code:
tr '\015' '\n' < input_file > output_file
 
Resolution!

It works! Thank you all for your assistance! I am obliged to each of you.
God bless.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.