string

GNU parallel: how to call exported bash function with empty string argument?

GNU parallel: how to call exported bash function with empty string argument? Scenario: $ process(){ echo "[$1] [$2] [$3]" ; } ; export -f process $ process "x" "" "a.txt" [x] [] [a.txt] Here we see that the 2nd argument is empty string (expected). $ find -name "*.txt" -print | SHELL=$(type -p bash) parallel process …

Total answers: 1

awk print between lines when "/" is part of the name

awk print between lines when "/" is part of the name I need to print lines between those that contain a "/" in the name. I tried with: awk ‘/+SOLUTION/ESTIMATES/,/-SOLUTION/ESTIMATES/’ $F > fil$F and awk ‘/+SOLUTION"/"ESTIMATES/,/-SOLUTION"/"ESTIMATES/’ $F > fil$F and awk ‘/"{+SOLUTION/ESTIMATES}"/,/"{-SOLUTION/ESTIMATES}"/’ $F > fil$F but the error is always more or less the same …

Total answers: 3

How does the `tr` command work?

How does the `tr` command work? I was playing around with tr and got some unexpected results. What is happening in these situations? I don’t understand what is happening under the hood, or perhaps I’m not using this command correctly. Example A echo ‘0123456789’ | tr [:digit:] ’12’ 1222222222 Example B1 echo ‘1111111111’ | tr …

Total answers: 2

How to convert all newlines to "n" in POSIX sh strings

How to convert all newlines to "n" in POSIX sh strings I have a string that contains newline characters. I want to escape all newlines in that string by replacing all newline characters with a string of two characters: "n". How can I do this in POSIX sh? Here’s the goal: $ printf ‘anbncnd’ | …

Total answers: 1

Finding on each folder if a subfolder respect the convention name according to the folder name?

Finding on each folder if a subfolder respect the convention name according to the folder name? i have a "sites" folder with a number of site folder named: bu.my-url.com dud.myurl.com [must-be-indentical_string].myurl.com etc On each site folder, I’d like to check if the /themes/amu_[must-be-indentical_string] is identical to the site folder name /sites/[must-be-indentical_string].myurl.com/themes/amu_[must-be-indentical_string] Would there be a …

Total answers: 1

Use SED to replace part of a current variable with user input variable

Use SED to replace part of a current variable with user input variable I’m trying to replace only part of the existing variable with a new user input variable as below: #Current Variable: gdbName=Test.MY.DOMAIN.COM <–I need to replace the "Test" (This can be any other string not just Test e.g. CDB79 etc.) part only in …

Total answers: 2

Tool to flatten yaml

Tool to flatten yaml Is there a tool to flatten yaml structure like this: foo: bar: baz: true into this: foo.bar.baz = true not sure what is this syntax name context: I need this for hcl, setting a lot of values like this: set { name = "foo.bar.baz" value = false } this is for …

Total answers: 2

how to print first word from a string with multiple words without space?

how to print first word from a string with multiple words without space? I have a shell script to print appimage filenames inside a folder like this #! /bin/bash Dir="$HOME/Applications/" Dir2="$HOME/Downloads/" cd -P "$Dir" for f in *.AppImage; do z=$(echo $f | head -n1 | awk ‘{print $1;}’) echo $z done now the output is …

Total answers: 4

How to print leading zeros (padding) in awk?

How to print leading zeros (padding) in awk? I am trying to print 99.11111 as 099.11 in AWK. I have tried the following variations without success. $ awk ‘{printf ("%000.2fn", $1);}’ <<< 99.111111 99.11 $ awk ‘{printf ("%3.2fn", $1);}’ <<< 99.111111 99.11 $ awk ‘{printf ("%03.2fn", $1);}’ <<< 99.111111 99.11 Asked By: ychaouche || Source …

Total answers: 1

Why grep does not work properly in this case?

Why grep does not work properly in this case? Consider a file file2.txt having the following content: P 89 24 -1.5388040474568784e+01 7.4421775186012660e+00 -1.3143195543234219e+03 1.3168884860257754e+03 8.0419002445999993e+01 44 0 0 -97 0 P 122 -4 -1.4869334602986523e+01 5.7316939411954255e+00 -1.3144161801429666e+03 1.3169704096915282e+03 8.0419002445999993e+01 44 0 0 -370 0 P 493 -24 -1.4690576431881317e+01 7.3848907323212831e+00 -1.3144620647251766e+03 1.3170224315489374e+03 8.0419002445999993e+01 62 0 0 -499 …

Total answers: 9

Bash function colouring from string input matching regex

Bash function colouring from string input matching regex I have a multi-line string that I use for printing in a bash script. docstring=" Headings -H, -H CNT, -H=CNT, -HCNT, –heading CNT, –heading=CNT Warnings -W, -W CNT, -W=CNT, -WCNT, –warning CNT, –warning=CNT Errors -E, -E CNT, -E=CNT, -ECNT, –error CNT, –error=CNT" echo "$docstring" I want to …

Total answers: 2

Multi-line documentation for bash inspired by lisp

Multi-line documentation for bash inspired by lisp I want to print some usage information for some functions. I customarily use echo or printf for each line. echo "-V, –version" echo " Display the version number and copyrights of the invoked tool." echo "-u, –usage" echo " Provides brief information on how to use this tool." …

Total answers: 2

How to delete a string in my files?

How to delete a string in my files? So I want to match all below then remove those lines of string. [MTT-5634](https://my.atlassian.net/browse/MTT-5634) [MCC-123](https://my.atlassian.net/browse/MCC-123) [MTT-7965]: https://my.atlassian.net/browse/MTT-7965 https://my.atlassian.net/browse/MTT-7965 I have tried sed -e ‘s/[(MTT|MCC)-[0-9]{3,4}?]?://g;s!.?http[s]?://S*!!g’ input.txt > output.txt Asked By: Beelzebub || Source You didn’t enable the -Extended regex, so you will need to escape a few special …

Total answers: 1

Convert comma separated string into json array

Convert comma separated string into json array I have the following string in bash "3.8,3.9,3.10" Is there a way using shell to convert it into a json array, i.e. ["3.8", "3.9", "3.10"] Asked By: pkaramol || Source Since the string (including its double quotes) seems to be a properly formatted JSON string, we could pass …

Total answers: 1

Extract text from first and last strings

Extract text from first and last strings I want to extract text from a string matching the first and last word string is a path : /path/to/the/file/app.apk(randomcharacters) and I want to extract text like /path/to/the/file/app.apk using something like this sed ‘//path/.apk/’ only sed command required as answer Asked By: decipher || Source You can use …

Total answers: 2

Why is my file with 10 random bytes larger than 10 bytes?

Why is my file with 10 random bytes larger than 10 bytes? So I have generated a random string of 10 bytes using the command openssl rand -hex 10 > result. My question is why does the resulting file have a size of 21 bytes? I haven’t encrypted so I am not expecting padding in …

Total answers: 1