How to change word after match? - bash

I would like to remove word after match:
I would like to change the following line:
Assertion failed: FILE: ../../test.cpp LINE: 350: error message:
to this:
Assertion failed: FILE: ../../test.cpp LINE: error message:

How about:
$ echo "Assertion failed: FILE: ../../test.cpp LINE: 350: error message:" \
| sed 's/LINE: [^ ]*/LINE:/'
Assertion failed: FILE: ../../test.cpp LINE: error message:

Related

Syntax error: end of file unexpected (expecting "fi"))

I have the below shell script.
#!/bin/sh
i=1
for label in 'Mod Name' 'Issue No' 'UT Status' 'Dev ID' 'Loc'; do
if ! grep -q "^ $((i++)). $label:" $1; then
cat <<- EOF
Proposed message does not satisfy this repository's exacting standards
It must match the template:
1. Mod Name: xxx
2. Issue No: xxx
3. UT Status: xxx
4. Dev ID: xxx
5. Loc: xxx
The proposed message does not contain the label: $label" >&2
EOF
exit 1
fi
done
It fails with below error.
28: /mtp-test/script.sh: Syntax error: end of file unexpected (expecting "fi"))
Why does this error occur?
I tried by removing the space/tab before "EOF" as shown below and it worked. I am not sure why space creates an issue.
#!/bin/sh
i=1
label='Mod_Name'
for label in 'Mod_Name' 'Issue No' 'UT Status' 'Dev ID' 'Loc'; do
if ! grep -q "^ $((i++)). $label:" $1; then
cat <<- EOF
Proposed message does not satisfy this repository's exacting standards
It must match the template:
1. Mod_Name: xxx
2. Issue No: xxx
3. UT Status: xxx
4. Dev ID: xxx
5. Loc: xxx
The proposed message does not contain the label: $label" >&2
EOF
exit 1
fi
done

Preg_match(): missing closing parenthesis

A plugin is generating the following error:
Got error 'PHP message: PHP Warning: preg_match(): Compilation failed: missing closing parenthesis at offset 946 - DeferJS.php on line 78
The line of code that generates the error:
if ( preg_match( '#(' . $exclude_defer_js . ')#i', $tag['url'] ) ) {
Thanks for any help
$exclude_defer_js must contain special characters.
Use preg_quote:
if ( preg_match( '#' . preg_quote($exclude_defer_js, '#') . '#i', $tag['url'] ) ) {

Error on certain line: Syntax error: "(" unexpected

Have an error "Syntax error: "(" unexpected" when execute an script:
sync.sh: 11: sync.sh: Syntax error: "(" unexpected
line 11 contains on this:
declare -a FOLDERS=('/scripts' '/backup')
and on the top of script have the interpreter:
#!/bin/bash
Execute the script with:
sh /wdmycloudex2/$(hostname)/scripts/sync.sh
/wdmycloudex2/RASPBIAN/scripts/sync.sh: 11: /wdmycloudex2/RASPBIAN/scripts/sync.sh: Syntax error: "(" unexpected
The firsts 11 lines:
#!/bin/bash
IP='10.0.1.7'
PORT='443'
HOSTNAME=$(hostname)
DATE=$(date +%d%m%Y_%H%M%S)
SOURCE='/scripts'
DEST='/wdmycloudex2'
declare -a FOLDERS=('/scripts' '/backup')
anybody know and explain what's the problem?
The header #!/bin/bash is ignored when you start the script with sh sync.sh.
It will go better with bash /wdmycloudex2/RASPBIAN/scripts/sync.sh or
chmod +x /wdmycloudex2/RASPBIAN/scripts/sync.sh
/wdmycloudex2/RASPBIAN/scripts/sync.sh

Laravel 5.3.19 Illuminate\Support\Str::class error syntax error, unexpected ';'

I got error when i use Str from Alliases
Aliases Declaration:
'Str' => Illuminate\Support\Str::class,
Usages:
<p>{{ Str::limit($notice->description,100)}}</p>
Error Type:
FatalErrorException in aae7b22b68f86ae3874e1bac917a810813cbf059.php line 380: syntax error, unexpected ';'

Bash script operand expected

I'm having a small problem with this following snippet and I'm not sure why. The error given is (line indicated):
*2: syntax error: operand expected (error token is "*2")
while [[ $numberServers -gt $newindex ]]; do
serverPort=$((9001+$(($newindex*2)))) <--- This line
clientPort=$(($serverPort+1))
newindex=$(($newindex+1))
localhostport=$((serverPort-2))
string=$(($string,localhost:$(($serverPort-2))))
...
Any help would be greatly appreciated.
The problem is that the variable newindex is empty, so the expression became:
$((9001+$((*2))))
check the initialization of newindex.
Example:
$ echo $((9001+$(($newindex*2))))
bash: *2: syntax error: operand expected (error token is "*2")
$ newindex=4
$ echo $((9001+$(($newindex*2))))
9009

Resources