Blanks in path/filename for Dyalog APL ⎕NGET - whitespace

I am trying to access a native file using the ⎕NGET system function on a Ubuntu Unix system.
This works fine as long as the path/filename string does not contain blanks. If the path contains blanks the file is not recognized.
What can I do to make it work?

I'm not sure what exactly goes wrong, but note that spaces should not be escaped in the argument to ⎕NGET:
⎕SH'echo hello world > my\ file.txt'
⎕←⊃⎕NGET'my file.txt'
hello world
Try it online!

Related

how to extract all prefix words from an ispell .mwl file in bash

I have an ispell huge .mwl file and I want to remove all the ispell suffixes to generate a simple text-only words dictionnary
using unix ispell, bash or perl commands.
Is there ispell command options to do that?
(in unix, the .mwl.gz files are located in the /usr/share/ispell/ directory)
a short extract non exhaustive of the file:
a/MRSY
A'asia
a'body
a'thing
aaa
AAAS
Aaberg/M
Aachen/M
Aaedon/M
AAeE
AAeE's
aaerially
aaerialness
Aaerope/M
AAgr/M
aah/DGS
aal/MS
Aalborg
Aalesund
aalii/MS
Aaliyah/M
Aalst/M
Aalto
aam
Aandahl/M
Aani/M
Aaqbiye/M
Aar/MN
Aara/M
Aarau
aardvark/MS
aardwolf/M
aardwolves
Aaren/M
Aargau
aargh
Aarhus
Aarika/M
aarogramme
I'm not sure what you mean by suffix but I'll assume it's the part following the / or ' in your sample text. You can do this with a simple pipeline from Bash.
cat something.mwl | perl -pe 's{[/\x27].*$}{}; ' > stripped_something.txt
The -p switch means to run perl in a pipeline. Whatever you pipe in will be put into $_ one line at a time, worked on, and then printed out. Notice I put \x27 for the apostrophe in the regex. Escaping it in the command line is a big pain. If there are any other characters that start a suffix you can put them in the character class.
You can do any other work on the line before printing it out this way too.
See the perlrun documentation for more about the -p switch.

windows grep redirect output to file

I'm working on windows and I want to find all the strings beetwen quotes, from a directory. For example, if I have this:
string s = "Hello World!"
The grep command should return me "Hello World!".
Here is how I do this:
grep -Roe \"[^\"]*\" directory
I need to redirect the output to a file but when I redirect the output, like this "grep -Roe \"[^\"]*\" directory > log" I get the following errors:
>: Invalid argument
log: No such file or directory
Do you know how can I solve this and redirect the output?
This is a very old question, and by now the OP has probably solved it... but for posterity, it's worth noting that the issue is to do with the compiler conventions (see this question, and find the answer headed "You aren't using a Unix shell. Quoting is different").
As you've discovered, while your expression will work fine at the command line, when it is used in conjunction with a redirect it gets parsed wrongly.
The solution is to escape the double quotes with a caret (^), not a backslash (\). And you need to escape the caret as well (with a caret). You should also enclose the entire search expression in single quotes.
Reformulating your command using caret-escaping (and enclosing in '') yields
grep -Roe '^"[^^^"]*^"' directory > log
I use this quite a bit to get style attributes from legacy HTML files (basically stuff written by a former coder who didn't believe much in separating content from presentation) - in which case I use
grep -iown 'style=^"[^^^"]*^"' index.html > styles.txt
It works like a charm.
Imagine a code repository where every in HTML file, even the p tags go something like <p style="margin-left:20px;margin-top:20px; font: normal 12px Arial; color#FFFFFF">. Sheesh.

Some symbols don't effect cmd commands while others do

I noticed that cmd seems to accept some characters at the ends of commands. for example all of the following function correctly:
cls.
cls;
cls(
cls\
cls+
cls=
cls\"whatever"
cls\$
cls\#
and these do not:
cls'
cls$
cls)
cls-
cls#
cls\/
Does anybody know why this happens?
Thanks in advance.
It depends on the batch parser.
;,= are general batch delimiters, so you can append/prepend them to the most commands without effect.
;,,= ,=; echo hello
;,cls,;,,
The . dot can be appended to the most commands, as the parser will try to find a file named cls (without extension) cls.exe cls.bat, and when nothing is found then it takes the internal command.
The opening bracket is also a special charcter that the parser removes without error.
The \ backslash is used as path delimiter, so sometimes it works but sometimes you could change even the command.
cls\..\..\..\windows\system32\calc.exe

BASH: Replacing special character groups

I have a rather tricky request...
We use a special application which is connected to a oracle database. For control reasons the application uses special characters which are defined by the application and saved in a long field of the database.
My task is to query the long field periodically and check for changes. To do that, I write the content by using a bash script in a file and compare the old and the new file with md5sum.
When there's a difference, I want to send the old file via mail. The problem is, that the old file contains these special characters and I don't know how to replace them with for example a string which describes them.
I tried to replace them on the basis of their ASCII code, but this didn't work. I've also tried to replace them by their appearance in the file. (They look like this: ^P ) This didn't work neither.
When viewing the file by text editor like nano the characters are visible like described above. But when using cat on the file, the content is only displayed until the first appearance of such a control character.
As far as I know there is know possibility to replace them while querying from the database because of the fact that the content is in a LONG field.
I hope you can help me.
Thank you in advance.
Marco
^P is the Control-P character, which is decimal 16 or hexadecimal 0x10, also known as the Data Link Escape (DLE) character in ASCII.
To replace all occurrences of 0x10 in a file with another string we can use our friend gsed:
gsed "s/\x10/Data Link Escape/g" yourfile.txt
This should replace all occurrences of characters containing the hex value 0x10 with the text string "Data Link Escape". You'll probably want to use a different string - this is just an example.
Depending on the system you're using you may be able to use the standard sed command if your version of sed recognizes the \xNN single-character escape codes. If there are multiple hex characters you need to replace you may want to create a file containing your sed commands, one for each hexadecmial character you need to replace, and tell sed or gsed to use the commands in the file - consult the sed or gsed man pages for how to do this.
Share and enjoy.
You can use xxd to change the string to its hex representation, then use xxd -r to convert back.
Or, you can use uuencode and uudecode.
One option is to run the file through cat -v. This replaces nonprinting characters with visible representations (using the ^ notation for control characters):
$ echo $'\x10\x12\x13\x14\x16' | cat -v
^P^R^S^T^V

How do I run Ruby files whose path contains non-ASCII symbols?

Running d:\ruby\test.rb is always successful.
Running the copy of this file path which is at d:\программирование\test.rb fails, apparently because it contains non-ASCII, Cyrillic in this case, symbols:
No such file or directory - D:\... (Errno::ENOENT)
What should I do to make it work?
I'm using Ruby 1.9 and Windows.
If you are creating your path like:
"d:\программирование\test.rb"
Then Ruby is treating the "\t" character as if is is escaped: It is converting \t into a tab before passing the filename to any routine. That character is illegal in a filename. Well, maybe not illegal, but a real pain to deal with and not what you expect.
Instead, use:
'd:\программирование\test.rb'
Or, better yet, let Ruby do the lifting and reverse your backslashes when you define the name. Ruby should do the right thing and convert them on the fly for you:
"d:/программирование/test.rb"

Resources