Link to home
Start Free TrialLog in
Avatar of oaktrees
oaktrees

asked on

Quickly Restructure a Simple List of Words Into .RIS File Format

Hi,


So!  I've got a long list of words that I need to regenerate in the 


.RIS


format - https://www.wikiwand.com/en/RIS_(file_format)


Nice thing is, it seems while there are SEVERAL rows in the RIS format, I need to use just two for my purposes.  


So, what would be the quickest way to take a list of about 100 or so words and go from


WORDS

alpha
beta
gamma


to...

RIS FILE READABLE LIST OF WORDS

TY  - BOOK
TI  - alpha

TY  - BOOK
TI  - beta

TY  - BOOK
TI  - gamma


Sincerely,


OT

Avatar of David Favor
David Favor
Flag of United States of America image

https://en.wikipedia.org/wiki/RIS_(file_format) provides the format overview, which seems straightforward to understand.

The simple solution seems to be, just write a script to ingest your words, then spit them out in .ris format.

Since this solution seem... obvious... likely you've already hit some problem...

Provide the script code you've written. What you expect to see, along with what you're seeing.

Likely someone can point out how to fix your script.
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Not familiar with RIS but based on the link you provided, a quick Powershell script?

Created a text file:  q.txt:
alpha
beta
gamma

Open in new window


foreach($line in Get-Content .\q.txt) {
        Write-Output "TY - BOOK`nTI - $line`nER -"
}

Open in new window


Ran in PowerShell and got the following output:
TY - BOOK
TI - alpha
ER -
TY - BOOK
TI - beta
ER -
TY - BOOK
TI - gamma
ER -

Open in new window

I'm new to Powershell so always like to flex my learning muscles.

This seems cleaner:
get-content q.txt|foreach {"TY - BOOK`nTI - $_`nER -"}

Open in new window


There are probably even 'better' ways.
Avatar of oaktrees

ASKER

Hi slightwv,

Ah!  Bless you, mate!  I'm thinking I may be even LESS familiar than you to Powershell! :P :))

I was able to set the restrictions to the right level.  

And, I can even see the list being created but...I can't figure out how to keep the Powershell window from closing.

Basically, I made a folder on the desktop and put the files in there like this:
User generated imageBut...can't get past this point.

What do you think is happening?

Thanks!

OT
ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@slightwv, +1 for your quote, "Do not fear the command prompt..."

I'll be using this from now on.
Hi slightwv!

C:\Users\user\Documents\Qtext> get-content list.txt|foreach {"TY - BOOK`nTI - $_`nER -"} | Out-File -FilePath tags.txt

Soooooooo COOL!  Do not fear the Command Prompt! :D

All SET! :D :D :D !!!

One question, please - in those links above they said I needed to set the Execution Policy to

RemoteSigned

I did that.  Did I need to?  And, if I change it back to

Restricted

Can I still run this wee command

C:\Users\user\Documents\Qtext> get-content list.txt|foreach {"TY - BOOK`nTI - $_`nER -"} | Out-File -FilePath tags.txt

at the Command Prompt?

T H A N K  Y O U ! ! !

Sincerely,

OT
>>Can I still run this wee command

No better way to know than to:  Just try it.

>>in those links above they said I needed to set the Execution Policy to

I too remember doing that BUT, going from memory, it was because I was manually running a .ps1 script file instead of just executing commands from the prompt window.

I don't do enough on the Windows side to script a TON of stuff in their own files.

I have a few things I do from time to time and they are simple enough that I just do the copy/paste into the PS command prompt window.
:))))))))))))))))))))))))))))))))!!!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Why use a one line command when a 34 line AutoHotKey script will do....  ;)

Yes, there are MANY alternatives but hard to beat a one liner that will work on ALL Windows machines. Well, unless you are still running Win98!
> Why use a one line command when a 34 line AutoHotKey script will do.... ;)

Well, I see your smiley, so I'll take it as a good-humored jab, but there are actually numerous very good reasons:

(1) OT asked me for an AutoHotkey solution in an EE PM.

(2) I prefer clarity over brevity in my code.

(3) OT asked me for an AutoHotkey solution in an EE PM.

(4) Your one-liner does no error checking. What if the input file does not exist? What if writing the output file fails? I suppose that simply letting the script crash is one way to go, but I prefer to catch errors and give the user a clear error message on what went wrong. Note that 15 of the 34 lines are for error checking and 5 of the lines are blanks for readability.

(5) OT asked me for an AutoHotkey solution in an EE PM.

Regards, Joe
Hi slightwv,
Btw, there's a bug in your code. According to the link that OT posted, the tags in RIS file format are composed of "two letters, two spaces and a hyphen". Your code has one space instead of two. Regards, Joe
Yep but I also mentioned I've never used RIS.  Easy enough fix so, meh.
Hi,

Thanks to you both, slightwv and Joe.  

Joe's right.  I don't know Powershell - or much at all about computers!  I wrote Joe a PM and he stepped right up to help.  When I see how generous Joe is with his time and expertise I am regularly amazed.  Thank you, Joe!

And, slightwv - you jumped right in head first, into an app you weren't even familiar with!  You had a fix figured out straightaway and even posted a refinement!  Thank you for that.

That's what's best about EE - the sustained contribution of so many experts.  I get deeply learned, actionable items every time I post.  Multiple solutions - this alloy is the strength.  Even though I'm just a humble researcher, when I get in a bind I always think to myself, "I have an IT team that I'll run this by.  They'll have the answers.".  That's EE.

Sincerely,

OT
Thanks for those kind words, OT...very nice to hear! Cheers, Joe
> I've never used RIS.

Same here. Never even heard of it, let alone used it. Was very grateful for OT's link to that page...could not have written the script without it.

> Easy enough fix

Yep...true of most bugs...once you find them. :) I'm really curious why RIS decided to use two spaces there...seems to me that one space would be fine. Also, it's interesting that the specs at that page do not define the requirements after the hyphen. Is a space required? Or two spaces? Or are no spaces ok? Or any number of spaces? All the examples there show one space, but that may or may not be the requirement.