Does fish shell support alphabetic range expansion? [duplicate] - fish

This question already has answers here:
How to generate letter sequence list in fish shell
(4 answers)
Closed 4 years ago.
In bash you can do this
echo {a..d}
and it will print
a b c d
How to do that in fish shell?
What I tried:
echo {a..d}
a..d
echo {a-d}
a-d
echo [a-d]
[a-d]
echo (seq 5)[a-d]
fish: Invalid index value
echo (seq 5)[a-d]
^
echo (seq 5)[a..d]
fish: Invalid index value
echo (seq 5)[a..d]
^
Does fish support alphabetic expansion at all?

Does fish support alphabetic expansion at all?
No.
Use normal brace expansion - {a,b,c,d}.

Related

Keep lines containing "list of different words" like pattern [duplicate]

This question already has answers here:
How to make sed remove lines not matched by a substitution
(4 answers)
Boolean OR in sed regex
(4 answers)
Closed 4 years ago.
How can I keep all lines matching all those words
toto OR titi OR clic OR SOMETHING and delete any other lines?
If I do sed '/toto/ p ' file I cannot select titi for example.
What I am looking for is something similar to a Perl Regular expression as
^ (word1|word2|word3|andsoon).*. However, I need it for sed because it will be integrated into a bigger sed script.
The goal is to keep all lines starting with word where word is any word from a set of words.
The answer here depends a bit on how your master script is called. Imagine you have a file with the following content:
foo
car
bar
and you are interested in the lines matching "foo" and "bar", then you can do:
sed '/foo\|bar/!d'
sed -n '/foo\|bar/!d;p'
sed -n '/foo\|bar/p'
all these will output:
foo
bar
If you would just do:
sed '/foo\|bar/p'
you actually duplicate the lines.
foo
foo
car
bar
bar
As you see, there is a bit of different handling depending on the usage of the -n flag.
-n, --quiet, --silent suppress automatic printing of pattern space
source: man sed
In general, my suggestion is to delete the lines you don't need at the beginning of your sed script.

Use separator other than / in sed [duplicate]

This question already has answers here:
Using different delimiters in sed commands and range addresses
(3 answers)
Closed 4 years ago.
I want to use sed on some text that contains backslashes, and want to avoid lots of escaped \/ characters.
How can I change the delimiter or separator character to be other than /?
In GNU sed, simply swap out the / for the character you wish to use:
% echo /// | sed 's_/_x_g'
xxx
\ can also be used, and must not be escaped (it fails when escaped as \\):
% echo xxx | sed 's\x\y\g'
yyy

What does ${1+"$#"} mean in a unix shell script? [duplicate]

This question already has answers here:
${1:+"$#"} in /bin/sh
(4 answers)
Closed 7 years ago.
I came across this construct while reviewing some older unix shell scripts, what does it mean, and why is is used?
${1+"$#"}
I found this explanation from unix haters handbook, page 152 of text (page 190 of the pdf). http://web.mit.edu/~simsong/www/ugh.pdf
It’s the way to exactly reproduce the command line arguments in the
/bin/sh family of shells shell script.
It says, “If there is at least one argument ( ${1+ ), then substitute in
all the arguments ( “$#” ) preserving all the spaces, etc. within each
argument.
If we used only “$#” then that would substitute to “” (a null argument)
if there were no invocation arguments, but we want no arguments reproduced in
that case, not “”.
Why not “$*” etc.? From a sh(1) man page:
Inside a pair of double quote marks (“”), parameter and
command substitution occurs and the shell quotes the results to
avoid blank interpretation and file name generation. If $* is
within a pair of double quotes, the positional parameters are
substituted and quoted, separated by quoted spaces (“$1
$2 …”); however, if $# is within a pair of double quotes, the
positional parameters are substituted and quoted, separated by
unquoted spaces (“$1” “$2” …).
I think ${1+“$#”} is portable all the way back to “Version 7 Unix.”
Wow! All the way back to Version 7.
Google should be your best friend! This is a similar questions asked almost 2 years ago.
https://unix.stackexchange.com/questions/68484/what-does-1-mean-in-a-shell-script-and-how-does-it-differ-from

How to pass a variable to sed [duplicate]

This question already has answers here:
Shell variables in sed script [duplicate]
(5 answers)
Closed 8 years ago.
I want to delete words into a line. For example:
I want to delete one word in this line
And I want to delete 'one' to obtain:
I want to delete word in this line
By passing the word through a variable. So far I have got:
WORD=one ; sed -n 's/"$WORD"//g' file.txt > newfile.txt
But, it doesn't do anything. Why not? And how can I make it work?
WORD=one ; sed -e "s/$WORD//g" file.txt > newfile.txt
the key moment is variable expansion. You have to be careful though because shell variable expansion may be sometimes not what you want. In hard cases you have to do something like this:
EXPANDVAR=one; NOEXPANDVAR=another; sed -e 's/'"$EXPANDVAR"'$NOEXPANDVAR//g' file.txt > newfile.txt
In this case sed will replace (remove) pattern one$NOEXPANDVAR , literally.

How can I change the 'sed' slash (/) delimiter in insert command? [duplicate]

This question already has answers here:
Using different delimiters in sed commands and range addresses
(3 answers)
Closed 1 year ago.
Changing the delimiter slash (/) to pipe (|) in the substitute command of sed works like below
echo hello | sed 's|hello|world|'
How can I change the delimiter slash (/) to pipe (|) in the sed insert command below?
echo hello | sed '/hello/i world'
I'm not sure what is intended by the command you mentioned:
echo hello | sed '/hello/i world'
However, I presume that you want to perform certain action on lines matching the pattern hello. Lets say you wanted to change the lines matching the pattern hello to world. In order to accomplish that, you can say:
$ echo -e "something\nhello" | sed '\|hello|{s|.*|world|}'
something
world
In order to match lines using a regexp, the following forms can be used:
/regexp/
\%regexp%
where % may be replaced by any other single character (note the preceding \ in the second case).
The manual provides more details on this.
The answer to the question asked is:
echo hello | sed '\|hello|i world'
That is how you would prepend a line before a line matching a path, and avoid Leaning Toothpick Syndrome with the escapes.