To delete everything between square brackets
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I need to find the line in a lvm.conf
file which starts with string, global_filter
and remove everything between the square brackets except "r/.*/"
.
There is only 1 line which starts with global_filter.
Before Removal:
global_filter = [ "a|^/dev/sda.*$|", "a|^/dev/sdb.*$|", "r/.*/"]
After the Removal, it should be -
global_filter = [, "r/.*/"]
linux sed
add a comment |
up vote
0
down vote
favorite
I need to find the line in a lvm.conf
file which starts with string, global_filter
and remove everything between the square brackets except "r/.*/"
.
There is only 1 line which starts with global_filter.
Before Removal:
global_filter = [ "a|^/dev/sda.*$|", "a|^/dev/sdb.*$|", "r/.*/"]
After the Removal, it should be -
global_filter = [, "r/.*/"]
linux sed
Okay, I suppose you know how to address a line insed
and you know thes
command, so the only problem is to define a good regex for your match? How about[.*,
? Now build your command or ask a specific question.
– Philippos
Jul 24 '17 at 11:20
Shouldglobal_filter
lines that do not contain"r/.*/"
be modified?
– Stéphane Chazelas
Jul 24 '17 at 11:27
Are you sure you want to leave the leading comma in?
– Stéphane Chazelas
Jul 24 '17 at 11:28
Yes I want the comma should be retained. And also only that line in the file should be modified.
– user7290726
Jul 24 '17 at 12:43
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I need to find the line in a lvm.conf
file which starts with string, global_filter
and remove everything between the square brackets except "r/.*/"
.
There is only 1 line which starts with global_filter.
Before Removal:
global_filter = [ "a|^/dev/sda.*$|", "a|^/dev/sdb.*$|", "r/.*/"]
After the Removal, it should be -
global_filter = [, "r/.*/"]
linux sed
I need to find the line in a lvm.conf
file which starts with string, global_filter
and remove everything between the square brackets except "r/.*/"
.
There is only 1 line which starts with global_filter.
Before Removal:
global_filter = [ "a|^/dev/sda.*$|", "a|^/dev/sdb.*$|", "r/.*/"]
After the Removal, it should be -
global_filter = [, "r/.*/"]
linux sed
linux sed
edited Nov 20 at 22:25
Rui F Ribeiro
38.2k1475125
38.2k1475125
asked Jul 24 '17 at 11:11
user7290726
348
348
Okay, I suppose you know how to address a line insed
and you know thes
command, so the only problem is to define a good regex for your match? How about[.*,
? Now build your command or ask a specific question.
– Philippos
Jul 24 '17 at 11:20
Shouldglobal_filter
lines that do not contain"r/.*/"
be modified?
– Stéphane Chazelas
Jul 24 '17 at 11:27
Are you sure you want to leave the leading comma in?
– Stéphane Chazelas
Jul 24 '17 at 11:28
Yes I want the comma should be retained. And also only that line in the file should be modified.
– user7290726
Jul 24 '17 at 12:43
add a comment |
Okay, I suppose you know how to address a line insed
and you know thes
command, so the only problem is to define a good regex for your match? How about[.*,
? Now build your command or ask a specific question.
– Philippos
Jul 24 '17 at 11:20
Shouldglobal_filter
lines that do not contain"r/.*/"
be modified?
– Stéphane Chazelas
Jul 24 '17 at 11:27
Are you sure you want to leave the leading comma in?
– Stéphane Chazelas
Jul 24 '17 at 11:28
Yes I want the comma should be retained. And also only that line in the file should be modified.
– user7290726
Jul 24 '17 at 12:43
Okay, I suppose you know how to address a line in
sed
and you know the s
command, so the only problem is to define a good regex for your match? How about [.*,
? Now build your command or ask a specific question.– Philippos
Jul 24 '17 at 11:20
Okay, I suppose you know how to address a line in
sed
and you know the s
command, so the only problem is to define a good regex for your match? How about [.*,
? Now build your command or ask a specific question.– Philippos
Jul 24 '17 at 11:20
Should
global_filter
lines that do not contain "r/.*/"
be modified?– Stéphane Chazelas
Jul 24 '17 at 11:27
Should
global_filter
lines that do not contain "r/.*/"
be modified?– Stéphane Chazelas
Jul 24 '17 at 11:27
Are you sure you want to leave the leading comma in?
– Stéphane Chazelas
Jul 24 '17 at 11:28
Are you sure you want to leave the leading comma in?
– Stéphane Chazelas
Jul 24 '17 at 11:28
Yes I want the comma should be retained. And also only that line in the file should be modified.
– user7290726
Jul 24 '17 at 12:43
Yes I want the comma should be retained. And also only that line in the file should be modified.
– user7290726
Jul 24 '17 at 12:43
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
sed -i -e '/^global_filter/' data
Explanation
sed -i -e '
# look at only lines that begin with global_filter
/^global_filter/"r/.*/"
' data
Thanks for the help. This replaces the entire file. I want only that line to be modified.
– user7290726
Jul 24 '17 at 12:44
I modified the command by replacing the -n flag by -i and it worked. It is working as expected but I am seeing a duplicate entry the next line.
– user7290726
Jul 24 '17 at 12:54
Can you please help me in that.
– user7290726
Jul 24 '17 at 12:55
Yes I tried with the first method itself. It is giving duplicate entry in the file.
– user7290726
Jul 24 '17 at 13:03
With -n option, the entire file is being replaced by just the global_filter line.
– user7290726
Jul 24 '17 at 13:14
add a comment |
up vote
0
down vote
Try this:
$ echo 'global_filter = [ "a|^/dev/sda.$|", "a|^/dev/sdb.$|", "r/.*/"]'|
sed -E 's/(^global_filter = [)(.*)(, "r.*$)/13/'
Output:
global_filter = [, "r/.*/"]
Just try on the input:global_filter = [ "a|^/dev/sda.$|", "a|^/dev/sdb.$|", "r/Dot_Star/"]'
– user218374
Jul 24 '17 at 11:24
Sorry John this is not working
– user7290726
Jul 24 '17 at 13:04
I mean for file input, I could not get this working.. can you help me out.
– user7290726
Jul 24 '17 at 13:15
@user7290726 I see. Could you please than post an excerpt of your input file to make it easier to guess what you want?
– John Goofy
Jul 24 '17 at 13:20
The file has only 1 line which starts with global_filter. And I need the changes as said earlier.
– user7290726
Jul 26 '17 at 2:55
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
sed -i -e '/^global_filter/' data
Explanation
sed -i -e '
# look at only lines that begin with global_filter
/^global_filter/"r/.*/"
' data
Thanks for the help. This replaces the entire file. I want only that line to be modified.
– user7290726
Jul 24 '17 at 12:44
I modified the command by replacing the -n flag by -i and it worked. It is working as expected but I am seeing a duplicate entry the next line.
– user7290726
Jul 24 '17 at 12:54
Can you please help me in that.
– user7290726
Jul 24 '17 at 12:55
Yes I tried with the first method itself. It is giving duplicate entry in the file.
– user7290726
Jul 24 '17 at 13:03
With -n option, the entire file is being replaced by just the global_filter line.
– user7290726
Jul 24 '17 at 13:14
add a comment |
up vote
1
down vote
accepted
sed -i -e '/^global_filter/' data
Explanation
sed -i -e '
# look at only lines that begin with global_filter
/^global_filter/"r/.*/"
' data
Thanks for the help. This replaces the entire file. I want only that line to be modified.
– user7290726
Jul 24 '17 at 12:44
I modified the command by replacing the -n flag by -i and it worked. It is working as expected but I am seeing a duplicate entry the next line.
– user7290726
Jul 24 '17 at 12:54
Can you please help me in that.
– user7290726
Jul 24 '17 at 12:55
Yes I tried with the first method itself. It is giving duplicate entry in the file.
– user7290726
Jul 24 '17 at 13:03
With -n option, the entire file is being replaced by just the global_filter line.
– user7290726
Jul 24 '17 at 13:14
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
sed -i -e '/^global_filter/' data
Explanation
sed -i -e '
# look at only lines that begin with global_filter
/^global_filter/"r/.*/"
' data
sed -i -e '/^global_filter/' data
Explanation
sed -i -e '
# look at only lines that begin with global_filter
/^global_filter/"r/.*/"
' data
edited Jul 24 '17 at 13:15
answered Jul 24 '17 at 11:21
user218374
Thanks for the help. This replaces the entire file. I want only that line to be modified.
– user7290726
Jul 24 '17 at 12:44
I modified the command by replacing the -n flag by -i and it worked. It is working as expected but I am seeing a duplicate entry the next line.
– user7290726
Jul 24 '17 at 12:54
Can you please help me in that.
– user7290726
Jul 24 '17 at 12:55
Yes I tried with the first method itself. It is giving duplicate entry in the file.
– user7290726
Jul 24 '17 at 13:03
With -n option, the entire file is being replaced by just the global_filter line.
– user7290726
Jul 24 '17 at 13:14
add a comment |
Thanks for the help. This replaces the entire file. I want only that line to be modified.
– user7290726
Jul 24 '17 at 12:44
I modified the command by replacing the -n flag by -i and it worked. It is working as expected but I am seeing a duplicate entry the next line.
– user7290726
Jul 24 '17 at 12:54
Can you please help me in that.
– user7290726
Jul 24 '17 at 12:55
Yes I tried with the first method itself. It is giving duplicate entry in the file.
– user7290726
Jul 24 '17 at 13:03
With -n option, the entire file is being replaced by just the global_filter line.
– user7290726
Jul 24 '17 at 13:14
Thanks for the help. This replaces the entire file. I want only that line to be modified.
– user7290726
Jul 24 '17 at 12:44
Thanks for the help. This replaces the entire file. I want only that line to be modified.
– user7290726
Jul 24 '17 at 12:44
I modified the command by replacing the -n flag by -i and it worked. It is working as expected but I am seeing a duplicate entry the next line.
– user7290726
Jul 24 '17 at 12:54
I modified the command by replacing the -n flag by -i and it worked. It is working as expected but I am seeing a duplicate entry the next line.
– user7290726
Jul 24 '17 at 12:54
Can you please help me in that.
– user7290726
Jul 24 '17 at 12:55
Can you please help me in that.
– user7290726
Jul 24 '17 at 12:55
Yes I tried with the first method itself. It is giving duplicate entry in the file.
– user7290726
Jul 24 '17 at 13:03
Yes I tried with the first method itself. It is giving duplicate entry in the file.
– user7290726
Jul 24 '17 at 13:03
With -n option, the entire file is being replaced by just the global_filter line.
– user7290726
Jul 24 '17 at 13:14
With -n option, the entire file is being replaced by just the global_filter line.
– user7290726
Jul 24 '17 at 13:14
add a comment |
up vote
0
down vote
Try this:
$ echo 'global_filter = [ "a|^/dev/sda.$|", "a|^/dev/sdb.$|", "r/.*/"]'|
sed -E 's/(^global_filter = [)(.*)(, "r.*$)/13/'
Output:
global_filter = [, "r/.*/"]
Just try on the input:global_filter = [ "a|^/dev/sda.$|", "a|^/dev/sdb.$|", "r/Dot_Star/"]'
– user218374
Jul 24 '17 at 11:24
Sorry John this is not working
– user7290726
Jul 24 '17 at 13:04
I mean for file input, I could not get this working.. can you help me out.
– user7290726
Jul 24 '17 at 13:15
@user7290726 I see. Could you please than post an excerpt of your input file to make it easier to guess what you want?
– John Goofy
Jul 24 '17 at 13:20
The file has only 1 line which starts with global_filter. And I need the changes as said earlier.
– user7290726
Jul 26 '17 at 2:55
add a comment |
up vote
0
down vote
Try this:
$ echo 'global_filter = [ "a|^/dev/sda.$|", "a|^/dev/sdb.$|", "r/.*/"]'|
sed -E 's/(^global_filter = [)(.*)(, "r.*$)/13/'
Output:
global_filter = [, "r/.*/"]
Just try on the input:global_filter = [ "a|^/dev/sda.$|", "a|^/dev/sdb.$|", "r/Dot_Star/"]'
– user218374
Jul 24 '17 at 11:24
Sorry John this is not working
– user7290726
Jul 24 '17 at 13:04
I mean for file input, I could not get this working.. can you help me out.
– user7290726
Jul 24 '17 at 13:15
@user7290726 I see. Could you please than post an excerpt of your input file to make it easier to guess what you want?
– John Goofy
Jul 24 '17 at 13:20
The file has only 1 line which starts with global_filter. And I need the changes as said earlier.
– user7290726
Jul 26 '17 at 2:55
add a comment |
up vote
0
down vote
up vote
0
down vote
Try this:
$ echo 'global_filter = [ "a|^/dev/sda.$|", "a|^/dev/sdb.$|", "r/.*/"]'|
sed -E 's/(^global_filter = [)(.*)(, "r.*$)/13/'
Output:
global_filter = [, "r/.*/"]
Try this:
$ echo 'global_filter = [ "a|^/dev/sda.$|", "a|^/dev/sdb.$|", "r/.*/"]'|
sed -E 's/(^global_filter = [)(.*)(, "r.*$)/13/'
Output:
global_filter = [, "r/.*/"]
edited Jul 24 '17 at 11:50
answered Jul 24 '17 at 11:21
John Goofy
556113
556113
Just try on the input:global_filter = [ "a|^/dev/sda.$|", "a|^/dev/sdb.$|", "r/Dot_Star/"]'
– user218374
Jul 24 '17 at 11:24
Sorry John this is not working
– user7290726
Jul 24 '17 at 13:04
I mean for file input, I could not get this working.. can you help me out.
– user7290726
Jul 24 '17 at 13:15
@user7290726 I see. Could you please than post an excerpt of your input file to make it easier to guess what you want?
– John Goofy
Jul 24 '17 at 13:20
The file has only 1 line which starts with global_filter. And I need the changes as said earlier.
– user7290726
Jul 26 '17 at 2:55
add a comment |
Just try on the input:global_filter = [ "a|^/dev/sda.$|", "a|^/dev/sdb.$|", "r/Dot_Star/"]'
– user218374
Jul 24 '17 at 11:24
Sorry John this is not working
– user7290726
Jul 24 '17 at 13:04
I mean for file input, I could not get this working.. can you help me out.
– user7290726
Jul 24 '17 at 13:15
@user7290726 I see. Could you please than post an excerpt of your input file to make it easier to guess what you want?
– John Goofy
Jul 24 '17 at 13:20
The file has only 1 line which starts with global_filter. And I need the changes as said earlier.
– user7290726
Jul 26 '17 at 2:55
Just try on the input:
global_filter = [ "a|^/dev/sda.$|", "a|^/dev/sdb.$|", "r/Dot_Star/"]'
– user218374
Jul 24 '17 at 11:24
Just try on the input:
global_filter = [ "a|^/dev/sda.$|", "a|^/dev/sdb.$|", "r/Dot_Star/"]'
– user218374
Jul 24 '17 at 11:24
Sorry John this is not working
– user7290726
Jul 24 '17 at 13:04
Sorry John this is not working
– user7290726
Jul 24 '17 at 13:04
I mean for file input, I could not get this working.. can you help me out.
– user7290726
Jul 24 '17 at 13:15
I mean for file input, I could not get this working.. can you help me out.
– user7290726
Jul 24 '17 at 13:15
@user7290726 I see. Could you please than post an excerpt of your input file to make it easier to guess what you want?
– John Goofy
Jul 24 '17 at 13:20
@user7290726 I see. Could you please than post an excerpt of your input file to make it easier to guess what you want?
– John Goofy
Jul 24 '17 at 13:20
The file has only 1 line which starts with global_filter. And I need the changes as said earlier.
– user7290726
Jul 26 '17 at 2:55
The file has only 1 line which starts with global_filter. And I need the changes as said earlier.
– user7290726
Jul 26 '17 at 2:55
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f381396%2fto-delete-everything-between-square-brackets%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Okay, I suppose you know how to address a line in
sed
and you know thes
command, so the only problem is to define a good regex for your match? How about[.*,
? Now build your command or ask a specific question.– Philippos
Jul 24 '17 at 11:20
Should
global_filter
lines that do not contain"r/.*/"
be modified?– Stéphane Chazelas
Jul 24 '17 at 11:27
Are you sure you want to leave the leading comma in?
– Stéphane Chazelas
Jul 24 '17 at 11:28
Yes I want the comma should be retained. And also only that line in the file should be modified.
– user7290726
Jul 24 '17 at 12:43