syslog-ng replacing double quotation with single quotation in MESSAGE - syslog-ng

In syslog-ng I am using particular template for formatting message format. Following is the template I am using
template t_noHeader {
template("{\"time\":\"$DATE\",\"logLevel\":\"$LEVEL\",\"log\":{[\"$PROGRAM\",\"$MSG\"]}}\n");
template_escape(no);
};
$MSG can sometimes contain "" which I want to replace with single quotation mark. Is it possible to do this in syslog-ng.conf file.

Try the replace-delimiter template function: https://syslog-ng.com/documents/html/syslog-ng-ose-latest-guides/en/syslog-ng-ose-guide-admin/html/reference-template-functions.html#template-function-replace-delimiter

Related

How to escape double quotes within a data when it is already enclosed by double quotes

I have CSV data separated by comma like below which has to be imported into snowflake table using copy command .
"1","2","3","2"In stick"
Since I am already passing the parameter OPTIONALLY_ENCLOSED_BY = '"' to copy command I couldn't escape the " (double quotes) within the data ("2"In stick") .
The imported data that I want to see in the table is like below
1,2,3,2"In stick
Can someone please help here ? Thanks !
If you are on Windows, I have a funny solution for that. Open this CSV file in MS Excel. Excel consumes correct double quotes to show data in the cellular format and leaves the extra in the middle of a cell (if each cell is separated properly by commas). Then choose 'replace' and replace double quotes with something else (like two single quotes or replace by nothing to remove them). Then save it again as a CSV. I assume other spreadsheet programs should do the same.
If you have an un-escaped quote inside a field which is surrounded by quotes that isn't really valid CSV. For example, here is an excerpt from the RFC4180 spec
If double-quotes are used to enclose fields, then a double-quote
appearing inside a field must be escaped by preceding it with another double quote.
For example:
"aaa","b""bb","ccc"
I think that whatever is generating the CSV file is doing it incorrectly and needs to be fixed before you will be able to load it into Snowflake. I don't think any file_format option will be able to solve this for you since it's not valid CSV.
The CSV row should either look like this:
"1","2","3","2""In stick"
or this:
"1","2","3","2\"In stick"
I had this same problem, and while writing up the question, I found an answer:
Import RFC4180 files (CSV spec) into snowflake? (Unable to create file format that matches CSV RFC spec)
Essentially, set:
Name
Value
Column Separator
Comma
Row Separator
New Line
Header lines to skip
{you have to decide what to put here}
Field optionally enclosed by
Double Quote
Escape Character
None
Escape Unenclosed Field
None
Here is my ALTER statement:
ALTER FILE FORMAT "DB_NAME"."SCHEMA_NAME"."CSV_SPEC3" SET COMPRESSION = 'NONE' FIELD_DELIMITER = ',' RECORD_DELIMITER = '\n' SKIP_HEADER = 1 FIELD_OPTIONALLY_ENCLOSED_BY = '\042' TRIM_SPACE = FALSE ERROR_ON_COLUMN_COUNT_MISMATCH = TRUE ESCAPE = 'NONE' ESCAPE_UNENCLOSED_FIELD = 'NONE' DATE_FORMAT = 'AUTO' TIMESTAMP_FORMAT = 'AUTO' NULL_IF = ('\\N');
As I mention in the answer, I don't know why the above works, but it is working for me. Go figure.

Escaping custom character in objective-c

I am working on macOS, not iOS, XCode 11.
My app allows in a specific location to enter text. This text can be anything. Once done it exports a csv which will be passed to an external process i cannot influence.
The issue: the external process uses semicolon ";" as a separator (csv is separated differently). If the user writes semicolon the external process will fail.
If I manually add an escaping backslash before each semicolon to the csv and then pass it to the external app it works.
What I need: having each semicolon escaped with ONE backslash in the final csv
What I tried
Escaping the whole text with quotation marks - fail
Escaping semicolons in objective-c before writing csv by trying
stringByReplacingOccurrencesOfString (look for #";" replace with #"\;" - compiler throws a warning that escape character is unknown - fail
Appreciate any help
UPDATE:
I also tried to set a double backslash like #Corbell mentioned but this leads in a double backslash in the exported CSV -> fail
I also tried to set a single backslash by using its unicode character:
[NSString stringWithFormat:#"%C;",0x5C]; --> "\\;"
Also failed and produces two backslashes in the final CSV (where i need ONE only).
In your stringByReplacingOccurencesOfString call, second parameter, try escaping your backslash with a backslash to make it a literal character to insert, i.e. #"\\;" - otherwise the compiler thinks you're trying to specify #"\;" as an escape sequence (backslash-semicolon) which is invalid.
Solved. It was the CSV Parser that added additional escaping characters. Once solved that it worked like a charm.

Escaping Double Quotes in Velocity

I have a string which i am getting
#set($locator=$dataElement.getLocator().get(0))
#set($selector = $locator.getSelector())
$selector is string type and it contains double quotes as well
when i am calling
executor.click(new Params("$selector",BY.$By));
selector have double quotes, which needs to be replaced with single quotes.
i tried with replacing but it is giving error
i referred question
Escaping quotes in velocity template
But this also don't solved my purpose
example
$selector can be something like
a[#href="somelink"]
and i want that to changed to
a[#href='someLink']
For velocity
$selector.replaceAll('"',"'")
replaces " with '
so something like:
executor.click(new Params("$selector.replaceAll('"',"'")",BY.$By));
this works fine

Escape character in DataWeave string

We are getting a value from a DB that contains a backslash (\). After going through DataWeave, we get 2 backslashes. Here it is how it looks:
How can we have only one backslash in the end? Can we use the replace function somehow? I tried and could not make it work.
I believe the reason why you see two backslashes is because backslash is a reserved character (see JSON spec) therefore DataWeave is automatically escaping the backslash, which is necessary so not to have your DB value corrupted.
In my opinion the double backslash is not a problem. You should get the right content upon consuming the JSON object.
You could try to put in an escape character of your choice
Eg: %output application/csv escape = " "
This should ideally replace "/" with " ".
Hope this helps.

Replace special qoutes with normal

In VB.NET how do I replace special opening and closing double quotes (“ and ”) with ASCII quotes (").
Ive tried
s = s.replace("“", """")
but it seems that Visual Studio consider the “ quote in my code to be a normal quote leaving me with an invalid statement.
Unfortunately VB.NET doesn't support escape sequences but you can use ChrW() to specify code point:
s = s.Replace(ChrW(&H201C), """")
That's for “, code for ” is &H201D. Note that using code points you're free to search & replace any Unicode character (not just what VB.NET has an escape for - like ").
For complete list see: http://unicode-table.com/en/
If you want to use a quotation mark inside a string, VB doesn’t know whether the quotation mark is supposed to end the string or not. In C#, this would be fixed by escaping the quotation mark, i.e. in place of """ you’d write "\"". In VB, the same is done by doubling the quotation mark, i.e. """".
Back to your curly quote. The same as for straight quotes applies according to the VB language specification (¶1.6.4). So to write a curly quote in code, try the following:
s = Replace(s , "““", "“")
a second way: s = Replace(s , ChrW(&H201C), "“")