Questions tagged [string]
String manipulation: extracting a part of a string, text replacement, formatting to a given width, etc.
804 questions
2
votes
1
answer
197
views
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" &...
-1
votes
2
answers
60
views
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
...
0
votes
2
answers
101
views
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."
...
0
votes
3
answers
195
views
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
...
0
votes
3
answers
213
views
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 ...
0
votes
1
answer
71
views
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-...
2
votes
1
answer
277
views
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, ...
0
votes
1
answer
42
views
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// ;
2
votes
5
answers
336
views
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
-1
votes
1
answer
45
views
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
1
vote
1
answer
72
views
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 ...
-1
votes
5
answers
169
views
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-...
0
votes
0
answers
63
views
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: ...
-1
votes
1
answer
107
views
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 > ...
2
votes
1
answer
147
views
How to check what character a variable contains and compare it with a number? [closed]
I have an hour record in which subsequent hours are written from 1 to 9 as numbers and then as subsequent alphabetic characters. I would like to save the time in a normal format, so I need to convert ...