2
votes
5answers
290 views

How to reverse a string made of digit in bash?

What is the best way to turn out digits in number? E.g. $ echo 123 | hook 321 $ echo 12358 | hook 85321
2
votes
4answers
102 views

Parsing process command-line arguments from pargs in a shell script

I get list of PIDs in my bash scripts (Java processes) and have to analyze their command-line arguments to determine which instance of server each PID corresponds to. At the moment I do it that way ...
1
vote
3answers
78 views

Script to split string

@terdon's answer provides this script: find . -type f -name "*mp3" | while read file; do album="$(basename "$(dirname "$file")")"; filename="$(basename "$file")"; ...
3
votes
2answers
104 views

Add thousands separator in a number

In python re.sub(r"(?<=.)(?=(?:...)+$)", ",", stroke ) To split a number by triplets, e.g.: echo 123456789 | python -c 'import sys;import re; print re.sub(r"(?<=.)(?=(?:...)+$)", ",", ...
5
votes
3answers
73 views

how do I set quotes around a variable so that the programs sees them as quote marks

I am trying to get quotes around a variable to make is just like I typed it in the terminal to get this script to work. it shows " quotes around the varibale " but still does not see it as quotes, as ...
1
vote
3answers
79 views

splitting the string in bash script

I am new to bash script. I am taking some input from user and checking details about that. Example: $HOME/Documents/test/one.txt I take the above string as an input and want to retrieve one.txt, I ...
3
votes
5answers
167 views

Comparing Indices of two strings

I have two double quoted strings of same length, that look like this: "$con" - (consists of spaces and *'s): * ****** *** ** * ** and ...
0
votes
2answers
613 views

Extract a sub-string out of a variable's value

I have a string in the form of segment_78787 which is stored in a variable called $ID in my shell script. I need to get the second part "78787" and assign it to another variable. I tried like ...
0
votes
2answers
206 views

search fitting ipv6 address for MAC-Address in neighbours

I have a list of possible to ip6 addresses converted MAC-addresses, that could be found in the output of ping6 ff02::1%wlan0 possible mac addresses are for example: 66:70:02:75:80:fe, ...
2
votes
2answers
834 views

Testing a string containing only spaces (tabs, or “ ”)?

My code below doesn't work: stringZ=" " if [[ "$stringZ" == ^[[:blank:]][[:blank:]]*$ ]];then echo string is blank else echo string is not blank fi Result: string is not blank # wrong ...
5
votes
2answers
3k views

Extracting a string, according to a pattern, in a bash script

In bash, suppose that I have a string strname: strname="ph7go04325r" I would like to extract the characters between the first "3" character and the last "r" character in strname, saving the result ...
3
votes
4answers
17k views

Splitting string by the first occurrence of a delimiter

I have a string in the next format id;some text here with possible ; inside and want to split it to 2 strings by first occurrence of the ;. So, it should be: id and some text here with possible ; ...
2
votes
3answers
437 views

Find word in sentence with Bourne Shell (sh)

I'm trying to determine if a particular word appears in a sentence using Bourne Shell (sh). For example: #!/bin/bash INPUT='Lorem ipsum dolor sit amet.' if [[ "$INPUT" == *dolor* ]] then echo ...
5
votes
2answers
965 views

Splitting bash command line argument

Is this the best way to split up a colon separated bash command line argument? #!/bin/bash hostlist=`echo $1| awk '{split($0,Ip,":")} END{for (var in Ip) print Ip[var];}'` for host in $hostlist do ...
1
vote
2answers
393 views

Checking if PATH contains $HOME/mydir and adding it if not (all in a script) [duplicate]

Possible Duplicate: keep duplicates out of $PATH on source I am not an expert with Unix scripting. Some of my scripts are located in $HOME/mydir. Unfortunately, they are not accessible from ...
7
votes
7answers
1k views

Bash - Continuous String Manipulation

#!/bin/bash FILE="$(basename "$1")" FILE="${FILE/%.jpeg/.jpg}" Is there anyway to glue these two lines together into a one-liner?
2
votes
2answers
7k views

Bash shell script to locate and remove substring within a filename

I am trying to write a bash shell script in Mac OS X 10.6 (which is called by an Automator Action) to rename TV show DVD rips that I have named badly over the years. I want to remove part of the text ...