Hello,
I have some text files with the same structure but different values.
Example:
“Name”: “JUAN”; “Apellido”: “Garcia”
We need the file to take the value between Name: and Apellido:, so it has to be JUAN.txt.
Thanks in advance.
Hello,
I have some text files with the same structure but different values.
Example:
“Name”: “JUAN”; “Apellido”: “Garcia”
We need the file to take the value between Name: and Apellido:, so it has to be JUAN.txt.
Thanks in advance.
Hi,
try this:
Kind regards, Eric
Thanks for your answer
Do you think it will work for all my documents? I mean, I need it to search for "Name: XXXXX ; in all my documents and take XXXXX as the name for each document. Obviously, XXXXX is unique for each one.
Thanks
Hi. Welcome to MacScripter.
It’s a bit confusing because in your example the individual words are all in quotes, while in the following line they’re not. If the example’s correct — and if the “Name”: and “Apellido”: are the first or only ones in the text — the text between them can be extracted very simply like this:
set txt to "\"Name\": \"JUAN\"; \"Apellido\": \"Garcia\""
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"\"Name\": \"", "\"; \"Apellido\":"}
set theName to text item 2 of txt
set AppleScript's text item delimiters to astid
set fileName to theName & ".txt" --> "JUAN.txt"
Otherwise, if the words aren’t actually quoted, just leave the quote characters out of the script:
set txt to "Name: JUAN; Apellido: Garcia"
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"Name: ", "; Apellido:"}
set theName to text item 2 of txt
set AppleScript's text item delimiters to astid
set fileName to theName & ".txt" --> "JUAN.txt"
Hi,
if i understand well, this is what you’re looking for. Pick one and try it on a couple of documents:
or
kind regards,
Eric
Yes, that’s what I meant, sorry if I didn’t explained it correctly.
I’ll try that script.
Thanks.