shell

Regex to extract version from string

痞子三分冷 提交于 2021-01-29 08:20:48
问题 I have a string which has below value String1=winos-app-1.2.0-4.20120308.InLinuxOS.x86_64 I need to extract only version from this string which is "1.2.0-4" I have tried regular expression as mentioned below with sed sed -ne 's/[^0-9]*\(\([0-9]\.\)\{0,1\}[0-9][^.]\).*/\1/p' but I am only getting result "1.2.0-", missing number after "-" which is 4. I tried correcting it but it is returning null. Kindly, advise 回答1: how about grep: grep -Po "(?<=-)[\d.-]*(?=.\d{8})" 回答2: This should work, and

Access and append local file from remote host in bash script

非 Y 不嫁゛ 提交于 2021-01-29 08:12:06
问题 From my bash script, doing ssh login to the remote host. Sending my config file along with a script to the remote host to access the variables. Code is as below: #!/bin/bash source ~/shell/config.sh script=$(cat <<\____HERE pubkeyarray=() privkeyarray=() for (( w=1; w<=3; w++)) do cleos create key --file key[$w].txt privatekey=$(sed -ne 's/^Private key: \([^ ]*\).*/\1/p' ~/key[$w].txt) pubkey=$(sed -ne 's/^Public key: \([^ ]*\).*/\1/p' ~/key[$w].txt) pubkeyarray+=("$pubkey") privkeyarray+=("

Windows path too long

天大地大妈咪最大 提交于 2021-01-29 07:38:07
问题 Following snippet shows how to extract the target of a shortcut in Windows: import win32com.client shell = win32com.client.Dispatch("WScript.Shell") fp = r'C:\very_long_path\to\a\link\file\shortcut.lnk' shortcut = shell.CreateShortCut(fp) #targetPath = "\\\\?\\"+shortcut.Targetpath # Does not help targetPath = shortcut.Targetpath The code above fails if the lnk file is on a too long path. How can I get the shortcut's target path in this case? 回答1: I believe the limitations you are facing are

Merge two rows of a file

徘徊边缘 提交于 2021-01-29 07:35:45
问题 I have a input file which has large data in below pattern. some part of data is shown below: Data1 C In; CP In; D In; Q Out; Data2 CP In; D In; Q Out; Data3 CP In; CPN In; D In; QN Out; I want my output as Data1(C,CP,D,Q) In C; In CP; In D; Out Q; Data2 (CP,D,Q) In CP; In D; Out Q; Data3 (CP,CPN,D,QN) In CP; In CPN In D Out QN; I tried code given in comment section below, But getting error. Corrections are welcome. 回答1: variation on @EdMorton suggestion - fixing the desired order of fields: $

Send HTML message with attachement (.pdf) from Shell

谁都会走 提交于 2021-01-29 07:29:56
问题 I understood how I can send a HTML message with sendmail doing: ( echo "From: me@example.com"; echo "To: you@example.com"; echo "Subject: this is my subject"; echo "Content-Type: text/html"; echo "MIME-Version: 1.0"; echo ""; echo "My <b>HTML message<\b> goes here!"; ) | sendmail -t I also manages to send an attachement with mail doing uuencode file.pdf file.pdf | mail -s "my subject" you@example.com but I fail to send an HTML message with an attachement (.pdf). Note that I failed to install

Git filter-branch to filter-repo : tags not rewritten

ε祈祈猫儿з 提交于 2021-01-29 06:42:04
问题 I've been trying to modify a script using git filter-branch that takes a git repository and separates it in multiple new directories by specifying subfolders of this directory. The new directories should only have the commits that modified their corresponding subfolders, hence the use of filter-branch. My goal being to change filter-branch by filter-repo for better performances. It used to create a new branch $branch then use this command : git filter-branch -f --prune-empty --tag-name-filter

Powershell function “if test-connection” true

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-29 06:33:13
问题 Heyy guys, i have a powershell script which is working fine but i want to expand it with another line. Here is what i have. $Path = "\\xyz\trigger1.txt" $Path2 = "$env:userprofile\xyz\trigger2.txt" if ((Test-Path $Path -PathType Leaf) -and (-not(Test-Path $Path2 -PathType Leaf))){ if((get-process "XXX" -ea SilentlyContinue) -eq $Null) { "not Running" copy-item "\\xyz\xyz\*" "$env:userprofile\def\" -recurse -ErrorAction SilentlyContinue start-sleep -s 5 } else { "running" stop-process -name

passing properties to child task of composed-task-runner app of spring cloud dataflow

∥☆過路亽.° 提交于 2021-01-29 06:18:07
问题 I am trying to run composed-task-runner of spring cloud data flow, which has 2 child tasks (A and B) within it. I am passing properties to my-composed-task, which has to be passed to child tasks too, but it is not passing into the child applications. Below are the commands which I am using: for the creation of task in dataflow shell: task create my-composed-task --definition "A && B" for launching the task in dataflow shell: task launch my-composed-task --arguments "--spring.cloud.task

Send unserialized & unescaped HTML file data to an API with a bash script

孤人 提交于 2021-01-29 06:08:04
问题 I wanted to create a bash script that takes an HTML file and sends it to several APIs. I have a test.html file with unserialized HTML data like this: <h2 id="overview">Overview</h2> <p>Have the source of truth in your own space at <strong>somewhere</strong></p> <pre> <code class="lang-javascript">function go() { console.log('code blocks can be a pain'); } go(); </code> </pre> I need to send the content of the file somehow to an API, like this: curl --location --request POST 'https://devo.to

SSH Remote command exit code

≡放荡痞女 提交于 2021-01-29 06:06:06
问题 I know there are lots of discussions about it but i need you help with ssh remote command exit codes. I have that code: ( scan is a script which scans for viruses in the given file) for i in $FILES do RET_CODE=$(ssh $SSH_OPT $HOST "scan $i; echo $?") if [ $? -eq 0 ]; then SOME_CODE The scan works and it returns either 0 or (1 for errors) or 2 if a virus is found. But somehow my return code is always 0. Even, if i scan a virus. Here is set -x output: ++ ssh -i /home/USER/.ssh/id host 'scan