jq reading filter from a file results in Invalid Syntax Error - command-line

filter.jq
".security = {hideVersionStringsWhenNotLogged: true}"
When trying to apply the filter,
jq --from-file filter.jq a.json
encountering the following error
jq: error: syntax error, unexpected INVALID_CHARACTER, expecting $end (Unix shell quoting issues?) at , line 1
tried all combinations of single and double quotes to no avail.
Any suggestions?
Thx

If you want the filter to be read from a file, do not enclose it in the quotation marks that are needed if the filter is specified on the command line.
So the contents of your filter.jq file could look like this:
.security = {hideVersionStringsWhenNotLogged: true}

Related

wget or curl throws -bash: syntax error near unexpected token `('

I am trying to download a file which has symbol "(" in it;s URL.
I tried using wget and curl. Bash is not allowing it to be processed and throws "-bash: syntax error near unexpected token `('".
Any idea how to resolve it?
You should escape the character by adding a "\" before it. Like \( or \)
Add single quotes ' or double quotes " around the URL.
I hope someone found this useful.
In my case, I want to curl this file name data (1).rar
then it should be write like this in the terminal
http://example.com/data%20\(1\).rar
I encountered the same problem and solved that issue just by adding double quotes to the command what I am passing.
for eg:
git checkout "<branch_name>"

Puppet sed and replace

Im learning Puppet and currently trying to install tomcat. While trying to replace the Catalina home on the startup.sh using sed in the exec block, Im facing the below error.
Error: Could not retrieve catalog from remote server: Error 400 on
SERVER: Syntax error at '|export CATALINA_HOME=' at
/etc/puppetlabs/code/environments/production/modules/tomcat/manifests/init.pp:26:58
on node agent
Current value of startup.sh
export CATALINA_HOME="/home/john"
export JAVA_HOME="/usr"
......
.....
Expected output
export CATALINA_HOME="/home/john/apache-tomcat-6.0.44"
export JAVA_HOME="/usr/java/default"
My code snippet
.......
exec { 'modify_file':
command => "sed -i 's|export CATALINA_HOME="/home/john"|export CATALINA_HOME="/home/john/apache-tomcat-6.0.44"|g' /home/john/apache-tomcat-6.0.44/bin/startup.sh"
path => '/bin',
}
Any help is really appreciated, thanks in advance.
Also, I had went thru the puppet documents regarding path atrribute of exec block but I'm not sure why it is being used and what should be my path value in my manifest file.
Your sed expression is likely broken due to quote mismatch.
You could simplify the sed command by using:
sed -i '/CATALINA_HOME=/s,/home/john,&/apache-tomcat-6.0.44,;/JAVA_HOME=/s,/usr,&/java/default,' /home/john/apache-tomcat-6.0.44/bin/startup.sh
The expression contains 2 commands for both CATALINA_HOME and JAVA_HOME. Both commands uses the same syntax to append the required string to the variable declaration.
/<regex>/s will perform the subsitution on line with the <regex>.
The , is the command separator. I usually use / unless the pattern to search is a directory path.
& is printing the pattern space, i.e. the matched pattern.
Had you already tried using the file_line resource type of puppetlabs-stdlib module instead of doing an exec call?
You can see how it works here.
Match parameter receive the old value and will be replaced by the value of line parameter. For example:
file_line { 'catalina':
ensure => present,
path => '/etc/catalina/startup.sh',
line => 'export CATALINA_HOME=\"/home/john/apache-tomcat-6.0.44\"',
match => 'export CATALINA_HOME=\"/home/john\"',
}

sed repetition-operator operand invalid *****

I have text files that contain ***** in some locations. I need to replace the ***** with 9.999. This obviously came from some formatting error, but I do not have the program that created the files I now have to work with. I tried using the following command in csh:
sed -i "" 's/*****/9.999/g' *.dat
However, as I expected, I get the following error message:
sed: 1: "s/*****/9.999/g": RE error: repetition-operator operand invalid
I'm assuming this is because ***** is considered a special operator or something like that, but I can't figure out how to exempt them while using the sed command.
Does anyone have a hint that could help?
sed -E 's/\*{5}/9.999/g' file

PostgreSQL syntax error at or near "$1"

sql"""copy updateTable
from $path
credentials 'aws_access_key_id=<my_access_key_id>;aws_secret_access_key=<my_secret_access_key>'
json '<path_to_s3_repository>'
gzip;""".update().apply()
Above command gives
org.postgresql.util.PSQLException: ERROR: syntax error at or near "$1"
when run on spark streaming using scala. What might be the issue? The resultant query runs fine when run from command line.
You cannot use a parameter with COPY.
You have to add the literal value of $path to the statement string and execute that.

Escape parenthesis in perl while logging output to file

I am logging the output of a cli which is the change set details to a log file using the following code:
This code works fine but when the change set details contains parenthesis i.e. () it is breaking and results in the below error.
sh: -c: line 0: syntax error near unexpected token `)'
sh: -c: line 0: `scm list changes 5313) ---$ ABC "Changed to Kill SNMP Agent upon stop( -r rtcuser >> WIassociatedtoComp.log'
My code is :
foreach $changeset(#cs_ids) {
my $getWIs = "scm list changes $changeset -r rtcuser";
`$getWIs >> WIassociatedtoComp.log`;
}
What can be done to escape these parenthesis and log this entry to log successfully.
The output looks like the $changeset variable contains shell meta characters. Try to enclose that in single quotes:
foreach $changeset(#cs_ids) {
my $getWIs = "scm list changes '$changeset' -r rtcuser";
`$getWIs >> WIassociatedtoComp.log`;
}
Is the output still the same? Then please insert into the loop:
print "$getWIs\n";