grep command; Display all lines of the file /etc/ssh/sshd_config starting with a letter [duplicate] - linux

This question already has answers here:
How to grep for case insensitive string in a file?
(3 answers)
grep lines that start with a specific string
(2 answers)
How to use the grep with globs patterns? (like we use it in find command)
(2 answers)
Regex to match only letters
(20 answers)
Closed 6 days ago.
Display all lines of the file /etc/ssh/sshd_config starting with a letter.
include capital letters as well
below is what i tried
#!/bin/bash
grep -i 'n*' /etc/ssh/sshd_config

Like this:
grep '^[[:alpha:]]' /etc/ssh/sshd_config

Related

How to add a variable to matched expression in sed? [duplicate]

This question already has answers here:
How to find/replace and increment a matched number with sed/awk?
(5 answers)
Closed 4 years ago.
Suppose I have the following Bash script:
#!/bin/bash
INCREMENT_BY=5
sed 's/20000/&+$INCREMENT_BY/g' old > new
I expect all occurrences of 20000 to be replaced by 20005, but instead they are replaced with 20000+$INCREMENT_BY. How can I make this work?
You should use double quote for eval variable, like:
sed "s/20000/$(( $INCREMENT_BY + 2000))/g" old

Sed - How to switch two words in a line [duplicate]

This question already has answers here:
exchange two words using sed
(5 answers)
Closed 5 years ago.
I'm trying to write a shell script that switches the first and third words in a line. In this case only strings that contain letters (both upper- and lowercase) count as words, everything else (numbers, punctuation, whitespace) is considered whitespace.
For example:
abc123def. ghi...jkl
would turn into:
ghi123def. abc...jkl
I tried the following, but it doesn't work:
sed 's/\([a-zA-Z][a-zA-Z]*\)[^A-Z^a-z]\([a-zA-Z][a-zA-Z]*\)[^A-Z^a-z]\([a-zA-Z][a-zA-Z]*\)/\3 \2 \1/' input.txt
With sed:
$ echo "abc123def. ghi...jkl" | sed -r 's/([A-Za-z]*)([^A-Za-z]*[A-Za-z]*[^A-Za-z]*)([A-Za-z]*)(.*)/\3\2\1\4/g'
$ ghi123def. abc...jkl

How to delete last found value in Bash [duplicate]

This question already has answers here:
Bash : extracting part of a string
(4 answers)
Closed 6 years ago.
Say I have a string 0.0.25, how do I delete the last part after dot (including it) to make it like 0.0? Note that last part can have variable number of digits.
In bash you can do the following:
echo "${var%.*}"
See the Shell Parameter Expansion section of the manual.
Using awk you could:
echo "0.0.25" | awk -F. '{print $1"."$2}'

Why is SED echoing rather than editing: sed '/^;text1/!b;:a;n;//ba;i\text2' [duplicate]

This question already has answers here:
How do I use a new-line replacement in a BSD sed?
(4 answers)
Closed 7 years ago.
sed '/^;date.timezone =/!b;:a;n;//ba;i\date.timezone = Europe/London' /etc/php.ini
You can probably guess Im creating a script for setting up LAMP servers.
In the above example the text is not replaced but instead the changes are displayed on the console.
I my goal was to insert date.timezone = Europe/London the last occurence of ;date.timezone =
Etan Reisner:
You aren't using the -i flag to tell sed to modify in place.

Replace a text with a variable [duplicate]

This question already has answers here:
sed substitution with Bash variables
(6 answers)
Closed 7 years ago.
How can I do this?
sed -i 's/wiki_host/$host_name/g' /root/bin/sync
It will replace wiki_host with the text $host_name.
But I want to replace it with the content of the variable..
I tried it with
sed -i 's/wiki_host/${host_name}/g' /root/bin/sync
It doesn't work either.
You need to use double quotes:
$ sed -i "s/wiki_host/${host_name}/g" /root/bin/sync
Your single quotes prevent the shell variable from being replaced with its contents.

Resources