3
votes
Accepted
Remove lines from a file that begin with and do not end with in bash
There are two clauses that must both be satisfied ("starts with i", "doesn't end with .conf"). For a line to be excluded from the output, each clause needs to be tested separately ...
- 73.8k
2
votes
Remove lines from a file that begin with and do not end with in bash
It seems you have two conditionals, if line starts with 'i' and on true if line doesn't end with '.conf'. Instead of doing it in one search, do it in two.
sed -i '/^i/{/\.conf$/!d}' /usr/local/choops/...
- 812
2
votes
Accepted
Modifying a path
In:
sed "s|"$(dirname "$var")"|.|g" "$filename"
The s| and |.|g are being quoted, but the $(dirname "$var") is out of the quotes, and is therefore ...
- 505k
1
vote
Modifying a path
This seems to be all you're trying to do, using any sed and assuming your variable doesn't contain any :s:
$ var='/dir/dir xyz/file.txt'
$ sed "s:$var:.:" file
dog foo/bar .
a b c d . x y z
....
- 27.3k
1
vote
Remove lines from a file that begin with and do not end with in bash
I want to remove all lines in a file that begin with the letter "i" and DO NOT end with ".conf"
Let A denote "begin with the letter i"
Let B denote "end with .conf&...
- 101k
1
vote
How can I replace multiple substrings from multiple lines in a file matching a pattern from a different file?
The following perl script reads in the first input file (ip_hostname.txt), and builds an associative array (hash) called %IPs, where the keys are the IP addresses and the values are the hostnames.
As ...
- 73.8k
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
sed × 7127awk × 2810
text-processing × 2298
grep × 932
bash × 924
regular-expression × 861
shell-script × 822
linux × 786
shell × 419
perl × 407
replace × 226
scripting × 180
command-line × 174
csv × 159
find × 132
xml × 128
string × 120
text-formatting × 120
files × 113
cut × 109
macos × 97
quoting × 83
json × 75
tr × 74
variable × 64