Searching for right double angle quotes on freebsd7 unix - grep

I know how to search for a string in files using grep
grep -Flr --include "*" 'string' files/
However how would I search for right double angle quotes ( » ) as the character will not appear in the terminal.

The double angle quotes are ASCII codes 174 (<<) and 175 (>>), if you are talking about ANSI character set and not Unicode.
You can try
grep `echo "\256"` file
256 is the octal ASCII value for <<. Note that octal value is enclosed in backquotes.

Related

How would I put “\” in a string without the apostrophe in the front of it being cancelled out?

For example, if I were to do this:
print(“\”)
It would say: `unfinished string near: ‘“”’
instead of my expected output of: ‘\’
How would I print this? I have searched on google yet still have yet to find an answer.
The backslash (\) is escaping the following character, being the double quote ("), causing the string to be unfinished.
To include an actual backslash in your string, you escape it with another backslash:
print("\\")
From Lua 5.4 Reference Manual, §3.1 (emphasis mine):
A short literal string can be delimited by matching single or double quotes, and can contain the following C-like escape sequences: '\a' (bell), '\b' (backspace), '\f' (form feed), '\n' (newline), '\r' (carriage return), '\t' (horizontal tab), '\v' (vertical tab), '\\' (backslash), '"' (quotation mark [double quote]), and ''' (apostrophe [single quote]). [...]

GREP to find a sequence of characters without a closing apostrophe

I'm trying to find long quotes in the text that I'm editing so that I can apply a different style to them. I've tried this GREP:
~[.{230}(?!.~])
What I need is for the GREP to find any 230 characters preceded by a left/opening quote mark, not including any 230-character sequence including a character followed by a right/clsoing quote mark. This should then eliminate quotes of less than 230 characters from the search. My GREP finds the correct length sequence but doesn't exclude those sequences which include a right quote mark.
So I want to find this, which my GREP does:
But not this, which my GREP also finds:
Because it has a closing quote in it and is therefore what I'm classing as a short quote.
Any ideas? TIA
You can match an opening ‘ followed by 230 or more occurrences of any character except an opening or closing quotation mark.
To not match the closing quotation mark, you can assert it using a positive lookahead.
‘[^‘’]{230,}(?=’)
‘ Match ‘
[^‘’]{230,} Repeat 230+ times any char except ‘ or ’ using a negated character class
(?=’) Positive lookahead, assert ’ directly to the right
See a regex demo.
Thanks #Thefourthbird.
So what I needed was:
‘[^’]{230,}
to search for an opening apostrophe ‘ followed by anything but a closing apostrophe [^’] of 230 characters or more {230,}
Strangely, if you use InDesign's code for left ~[ and right ]~ apostrophe it doesn't work!

How to split by special character "\" in Lua?

I tried to split by "\", but this character is so special in Lua, even if I use escape character "%", the IDE shows an error Unterminated String constant
local index = string.find("lua. is \wonderful", "%\", 1)
To insert backslash \ into a quoted string, escape it with itself: "\\". \ is the escape character in regular quoted strings, so it is escaped with \. Or you can use the long string syntax, which doesn't allow escape sequences, as already pointed out: [[\]].
Percent is only an escape character in a string that is being used as a pattern, so it is used before the magical characters ^$()%.[]*+-? in the second argument to string.find, string.match, string.gmatch, and string.gsub, and %% represents % in the third argument to string.gsub.
The percent is still there in the string that is stored in memory, but backslash escape sequences are replaced with the corresponding character. \\ becomes \ when the string is stored in memory, and if you count the number of backslashes in a string "\\" using string.gsub, it will only find one: select(2, string.gsub("\\", "\\", "")) returns 1.

grep pattern single and double quotes

Is there any difference between enclosing grep patterns in single and double quotes?
grep "abc" file.txt
and
grep 'abc' file.txt
I'm asking since there's no way I could test all possible cases on my own, and I don't want to stumble into a case that I get wrong :)
I see a difference if you have special characters :
Ex :
grep "foo$barbase" file.txt
The shell will try to expand the variable $barbase, this is maybe not what you intended to do.
If instead you type
grep 'foo$barbase' file.txt
$bar is taken literally.
Finally, always prefer single quotes by default, it's stronger.
In double quote, the following characters has special meanings: ‘$’,
‘`’, ‘\’, and, when history expansion is enabled, ‘!’.
The characters ‘$’ and ‘’ retain their special meaning within double
quotes ($ for variables and for executing).
The special parameters ‘*’ and ‘#’ retain their special meaning in
double quotes as inputs when proceeded by $.
‘$’, ‘`’, ‘"’, ‘\’, or newline can be escaped by preceding them with
a backslash.
The backslash retains its special meaning when followed by ‘$’, ‘`’,
‘"’, ‘\’, or newline. Backslashes preceding characters without a
special meaning are left unmodified.
Also it will be helpful to check shell expansions:
https://www.gnu.org/software/bash/manual/html_node/Shell-Expansions.html#Shell-Expansions
Single quote ignore shell expansions.

Load testing tool URL encoding system

I have a load testing tool (Borland's SilkPerformer) that is encoding / character as \x252f. Can anyone please tell me what encoding system the tool might be using?
Two different escape sequences have been combined:
a C string hexadecimal escape sequence.
an URL-encoding scheme (percent encoding).
See this little diagram:
+---------> C escape in hexadecimal notation
: +------> hexadecimal number, ASCII for '%'
: : +---> hexadecimal number, ASCII for '/'
\x 25 2f
Explained step for step:
\ starts a C string escape sequence.
x is an escape in hexadecimal notation. Two hex digits are expected to follow.
25 is % in ASCII, see ASCII Table.
% starts an URL encode, also called Percent-encoding. Two hex digits are expected to follow.
2f is the slash character (/) in ASCII.
The slash is the result.
Now I don't know why your software chooses to encode the slash character in such a weird way. Slash characters in urls need to be url encoded if they don't denote directory separators (the same thing the backslash does for Windows). So you will often find the slash character being encoded as %2f. That's normal. But I find it weird and a bit suspicious that the percent character is additionally encoded as a hexadecimal escape sequence for C strings.

Resources