Questions tagged [string]
String manipulation: extracting a part of a string, text replacement, formatting to a given width, etc.
805 questions
0votes
2answers
15views
Making each word in a text file an item in a bash array
I have a string of text and spaces which looks like this: macOS windows arch-linux ubuntu_linux I want to append each item (with whitespace denoting a break between items) to a bash array. How do I ...
2votes
1answer
198views
How can I take a sub-array in bash of the first N elements of a string array with elements containing spaces?
This question is similar to this one but it differs from it: Consider this array with string elements which may contain spaces: a@W:$ arr=("eins" "zwei" "eins plus zwei" &...
-1votes
2answers
60views
Split string with 0-2 / (or determine there's none) (Bash)
Update: Up to 2 "/" in the string. String structure is either: Character set name/LF Character set name/CRLF Character set name/CRLF/(unknown purpose, likely a number) Character set name ...
0votes
2answers
101views
How to check value inside a file using bash?
I'm trying to check if the value inside a file is "0". COUNT_EXECUTION=$(< /tmp/count) if [ "$COUNT_EXECUTION" == "0" ]; then echo "Try restart service." ...
0votes
3answers
196views
How to edit a string matching a pattern in a specific field on the condition another string is not present on the same line
I need to edit the string "NA" to "Na" only if it is in the 6th field of a file. I can currently achieve this with: awk '{gsub("NA","Na",$6)}1' $filename ...
0votes
3answers
217views
Convert json data to comma separated string
I have a json object that has an unknown number of variables, like this: { "var1": 123, "var2": 456, "var3": 789 } How can I automatically convert it to form ...
0votes
1answer
71views
Problem matching new terminal window ID with xdotool in Bash
I have a script that kicks off a new terminal window that I want to move to a specific position on the left terminal using xdotool. After kicking off the terminal I run xdotool search --class gnome-...
2votes
1answer
277views
Joining 'fish shell' arguments into a single string with spaces
Sorry, this question is already answered for 'bash' here: Joining bash arguments into single string with spaces. in Fish, using "'$*'" leads to this error: $* is not supported. In fish, ...
0votes
1answer
42views
What does the line ($eachJOBID = $eachScriptNoPath) =~ s/\.csh// ; do?
This line I have in my code cuts the .csh from a string and returns the rest of it. Can someone explain what each part of it does? ($eachJOBID = $eachScriptNoPath) =~ s/\.csh// ;
2votes
5answers
338views
How to remove duplicate slashes from path to a file?
I have a path to a file that has duplicate slashes which would like to simplify. For example, if I have the following: /opt//bin//executable I would like to get: /opt/bin/executable
-1votes
1answer
45views
I can't grep some inputrc string
bind -p |grep -E "\\e.\":" work but bind -p |grep -E "\\e\\C-.\":" don't work I tried a lot of combination
1vote
1answer
72views
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 ...
-1votes
5answers
169views
add empty line before every line that contains certain characters
I have a lot of markdown files that contains something like this: * header A - item 1 - item 2 ** sub-header A1 ** sub-header A2 * header B - item 1 - item 2 ** sub-header B1 ** sub-...
0votes
0answers
63views
Why isn't passed quoted $@ a single argument? [duplicate]
Why isn't passed quoted $@ a single argument? f2() { echo "f2: $1" } f1() { local x=("$@") f2 "${x[@]}" } f1 x y Invocation: $ bash t537.sh f2: ...
-1votes
1answer
107views
Checking if I'm correct about the order of operations in Bash
Guten Tag! I'm a rookie in everything Bash-related. I'm familiarizing with the syntax and wanted to know if the order of operations in this command is as I thought or not. The command: echo 2 * 3 > ...