The tag has no wiki summary.

learn more… | top users | synonyms

3
votes
1answer
173 views

What does the hash in ${parameter/#pattern/string} do?

I saw the following substitution in this article: ${PWD/#$HOME/~} How does it compare to this? ${PWD/$HOME/~} Both seem to be the same. I don't know why the hash was included.
2
votes
2answers
63 views

Creating an array with IFS set to a different value

I am trying to construct an array and write to a file in this format, i.e. the file's content should be something like this hero_pairscore=( askdjfh sdf,sdlkfj lksf,dfgdf,dsflkgj,asdlkf ....) Where ...
2
votes
2answers
42 views

How can I select a beginning…ending portion of a '/' delimited string (PS1 prompt in my case)

I am customizing my PS1 prompt, specifically the $PWD part which is delimited by /'s among several things I like having the current directory. However if the directory is too long I'd like to have ...
2
votes
1answer
38 views

How to print strings matching a pattern with grep?

I want to get a list of strings matching the following pattern: CLASS_NAME:"*" where * represents any number of characters. I tried: grep -o CLASS_NAME:\".*\" script.js and grep -o ...
0
votes
3answers
34 views

How to find the difference in tokens in two strings using Unix tools?

I have two strings as below- token1, token2, token3, token4, token5, token6, token8, token9, token10 token2, token7, token4, token3, token5, token6, token8, token10, token9 Visually, I can see ...
6
votes
6answers
374 views

bash find lines starting with string

I have a bunch of files and I want to find which one contains sequential lines starting with a certain string. For example for the following file : Aaaaaaaaaaaa Baaaaaaaaaaa Cxxxxxxxxx Cyyyyyyyyy ...
2
votes
2answers
148 views

How to find and replace a field column value in UNIX

I have file with the value say which is delimited with | 123-|aaa|bbb|123|123.0|123-|123.01-|-123.02|123.03-|aaa|bbb|123-|aaa-|-bbb|cc-cc|123.04-|aa123-|123.05- I need to pick the column values ...
2
votes
5answers
296 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
104 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 ...
0
votes
0answers
12 views

How to concatenate an echoed string to include literal single quotes around a value pulled from MySQL? [migrated]

I've run into a slight dilemma when I try to contain a value from an array of data pulled from MySQL inside single quotes. This would normally be a no brainer, but I run into issues since it's inside ...
2
votes
4answers
95 views

Compare two text files and find matching lines

I have two files A and B. A looks like this (4 to 6 lines): GAGA CAGA GGGT TATT file B is a really big file with thousands of lines, here is a short example: AAATGTCAAGAGACAGAAATGTCAAGAGGGT ...
7
votes
3answers
442 views

How to remove a specific character in a string but only if there are no numbers in that line in Linux

I've been stumped with this seemingly simple-to-fix problem.. well, for a while. Here's example output from the file I need to edit: $cat file George Washington Geneva Convention 123,281,029 USD ...
1
vote
3answers
162 views

How to loop a read function in Bash Script?

I needed to remove spaces and capital letters to various strings of text like: "My Name is Mauro" -> "my_name_is_mauro" So I have created this bash script:lowercase_underscore.sh (call it the ...
5
votes
6answers
205 views

How to match exact string using `sed`? But not the part of it.?

I have a input file FILE1.TXT as below. 11 id1 12 13 AGE = 20 14 NAME = NAME1 15 16 id2 17 18 AGE = 30 19 NAME = NAME2 . . . 110 idXYZ 111 112 AGE = AGEXYZ 113 NAME = ...
5
votes
2answers
103 views

ls for cut -f string not working

I have a problem with feeding cut output to ls. This doesn't work: rep="S1_1000,0000-00-00c,0000-00-00d,0000-00-00e" ls tab_yeast/{`echo $rep | cut -f2- -d','`}*.tab.gz ls: cannot access ...
3
votes
3answers
46 views

string substitutions: all occurrences

A simple question, but I can't find the answer. the zsh documentation overwhelms me :-( function z () { echo ${1:s/the/THE} } $ z thethethe THEthethe ... How can I get all 'the' to be replaced ...
1
vote
3answers
81 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")"; ...
1
vote
1answer
34 views

Is there a simple way to get array of all arguments that do not begin with a hyphen?

zsh includes a powerful utility for parsing command-line options zparseopts, but for quick shell scripts and shell functions, but is there an easy way to extract the array of all command-line ...
3
votes
2answers
110 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"(?<=.)(?=(?:...)+$)", ",", ...
2
votes
3answers
59 views

Sed - string substitution with groupings

I have a largish directory with filenames formatted like Some_Folder-(FOL001)-clean what I'm trying to do is display the pattern between the brackets at the start like FOL001 ...
0
votes
1answer
32 views

create an alias that runs a command with string replacement from arguments [duplicate]

I'm trying to write a couple of shortcut aliases to quickly navigate to the httpdocs folders of the various domains and subdomains on my server. basically so I can type something like: $ pwd / $ # ...
1
vote
3answers
45 views

Match a single character in a string bash script

My issues is that I want to read a character from the stdin and compare it with a string value. If that character exists then I want to display a message. Eg, saving % into the variable $a: $ read a ...
2
votes
5answers
606 views

Extract date from a variable in a different format

Let me explain you the problem $ date +%c -d "$d" Tue 31 Dec 2013 01:13:06 PM CET $ date +'Today is %F' -d "$d" Today is 2013-12-31 This solution corresponds to current date. But I have one ...
0
votes
0answers
15 views

UNIX: How to extract date from a variable storing a UNIX DATE [duplicate]

I am facing following issue: Input: F=`date +%Y%m%d` echo $F Output: F=20131231 But when trying this(File Name:A.sh): C=`date` G=`$C +%Y%m%d` echo $C echo $G Output: A.sh[6]: Tue: not ...
1
vote
1answer
133 views

Problem with sed on a array containing strings containing spaces

I have a array looking like this: array=("(1 2 3) (123)" "2 31 (231)" "4 5 1 (451)" "(te)xt (1234)") This array is a example. It does not look like this but its structure is the same (the strings ...
2
votes
6answers
1k views

bash - replace space with new line

How can I replace spaces with new lines on an input like: /path/to/file /path/to/file2 /path/to/file3 /path/to/file4 /path/to/file5 etc... To obtain the following: /path/to/file /path/to/file2 ...
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 ...
2
votes
3answers
60 views

Change value of a strings representing number

I have the following expression : a="2013" How can I change the value of a to "2012".
1
vote
1answer
40 views

Looping through commands' results, KSH script

I'd like to put two strings in two different variables. Let's take a small example. after a simple grep, I got this : $ grep nl.*acc.*bas : ABAS01=... ABAS02=... I'd like to have two variables, ...
1
vote
3answers
78 views

a string representation using regex (modified)

I would like to use regular expression to represent a pattern with the following type of characteristics 1) It includes a continuous sequence of digit values. The length of this sequence it at least ...
0
votes
1answer
174 views

Test variable if its string or not

I'm writing a script which will have some arguments and so I am using getopts but i want to solve the problem with one argument. I use a switch, for example -d, and I want the argument for -d will ...
3
votes
2answers
1k views

Bash : compare two strings with space

I am trying to write a bash script which run a command and compare the result with another string. #!/bin/bash -x STATUS=`/root/setup_ha show --password-file=/root/password | grep ">HA State" | ...
1
vote
3answers
80 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 ...
1
vote
0answers
49 views

Automatic replacement of strings in gedit

I want to replace some strings defined by me in gedit, after a word has been completed and/or the document has been saved. For example \ðrac should be replaced with \frac How do I do this in gedit or ...
0
votes
2answers
124 views

Transform list of files (with date) into list of dates

I have a directory where I store backups. The are in the format Complete Backup YYYY-MM-DD hh-mm-ss.tar.bz2 I have found out that you can feed a date into the date command using date --date="YY-MM-DD ...
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 ...
2
votes
4answers
391 views

Can awk use field identifiers also for shell strings (variables)?

Well, this apparently is not possible the way I'm trying it. This alternate approach to obtain bar as a resulting string works, though: #!/bin/bash path1=/usr/tmp/foo/bar/baz awk -F/ '{print $5}' ...
0
votes
2answers
635 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 ...
2
votes
1answer
68 views

strings command printing some extra characters

I am trying to capture mysql traffic using tcpdump and converting it to text using strings command, but while capturing mysql traffic, I am getting some extra character at the end of each character. I ...
2
votes
1answer
227 views

IPTables string match redirection

The issue: I am currently redirecting port 80 requests to another system on port 1000. This is done like so: iptables -t nat -A PREROUTING ! -s 172.20.1.2 -p tcp --dport 80 -j DNAT --to-destination ...
4
votes
2answers
293 views

Convert MAC address to Link-local address with bash

How can I convert a Mac address into an ipv6 Link-Local address? you have to add fe80:: at the start and insert ff:fe in the middle furthermore all leading zeros must be stripped
0
votes
2answers
208 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
1answer
122 views

shell parameter substitution to rename files

I need to rename filenames which starts with "foo" into "boo" This is the script I used #!/bin/sh for f in *.jpg; do mv -- "{$f}" "${f/foo/boo}"; done but when i run I get a bad substitution ...
2
votes
2answers
856 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 ...
3
votes
3answers
6k views

How to get the first word of a string?

When I 'echo *' I get the following output: file1 file2 file3 ... What I want is to pick out the first word. How can I proceed?
0
votes
3answers
242 views

Extract the base file name from a URL

url=http://www.foo.bar/file.ext; echo ${url##/*} I expected this code to print file.ext, but it prints the whole URL. Why? How can I extract the file name?
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 ...
2
votes
5answers
728 views

Test if a string has a period in it with bash

I want to run a bash command on output from Drupal's drush command-line interface. drush site-alias returns a list of webroots, first showing the name of the group, and then each site in that group. ...
10
votes
5answers
799 views

Pattern matching on path names in bash

I want to act on a list of subdirectories in a directory. Consider: for x in x86-headers/*/C/populate.sh; do echo $x; done This gives x86-headers/elf/C/populate.sh x86-headers/gl/C/populate.sh ...
1
vote
2answers
1k views

Pattern matching from the input arguments

we're trying to enhance the scripts. Users will pass some arguments and part of the arguments will have 5.0.3 For an example the input argument would be like Jboss5.0.3GA. Since it ( Jboss5.0.3GA ) ...