ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi gurus.
I would like ask question how use sed command with include and exclude patterns.
I have line, that started with " and ended with ",and include delimiters "|" between fields
example:
"3bd3ce4c-8839-4d55-bca7-8ad27cddf7f6"|"2e0636c6-400b-4cfe-b63b-a14a0de723f8"|"21713280"|"eb38a6a4-6b0a-496a-b2f7-63c33b21a706"|"We do not "allow" ""SSH"" into Erlang"|"03fb9da3-98a1-4cbe-8aef-d4f9d28e7065"|"2021-06-2 11:32:19.257000"|"2021-06-28 11:32:19.257000"
Using sed '/^"/,/$"/ {s/""/==/g}' will replace "" on SSH word
I need replace " near allow (just as example) and not my delimiter "|"
My input line from file is:
"3bd3ce4c-8839-4d55-bca7-8ad27cddf7f6"|"2e0636c6-400b-4cfe-b63b-a14a0de723f8"|"21713280"|"eb38a6a4-6b0a-496a-b2f7-63c33b21a706"|"We do not "allow" ""SSH"" into Erlang"|"03fb9da3-98a1-4cbe-8aef-d4f9d28e7065"|"2021-06-2 11:32:19.257000"|"2021-06-28 11:32:19.257000"
Desired output need to be:
"3bd3ce4c-8839-4d55-bca7-8ad27cddf7f6"|"2e0636c6-400b-4cfe-b63b-a14a0de723f8"|"21713280"|"eb38a6a4-6b0a-496a-b2f7-63c33b21a706"|"We do not allow ==SSH== into Erlang"|"03fb9da3-98a1-4cbe-8aef-d4f9d28e7065"|"2021-06-2 11:32:19.257000"|"2021-06-28 11:32:19.257000"
Hi
SSH is just example. I need generic code, that replace "" with == and " with ==
but not replace " on the start and the end of line and not replace my delimiter "|"
Thanks
and again, please use code tags. Do you understand it? I also attached a link to the documentation.
Without that you cannot distinguish between " and '' (or it is extremely hard) which makes your examples useless.
Code:
Within code tags it is quite easy: " and ''
sed "s/''([^|]*)''/==$1==/" or something similar?
Or probably like this:
I need replace " near allow (just as example) and not my delimiter "|"
Not good enough - for regex, you have to define the requirements exactly. Only double quotes around words that precede two double quotes ?; double quotes around words anywhere ?; what's a word in this context ?.
Regex can be constructed to do any of the above, but likely not (simply) in one execution - sed supports multiple -e in one command invocation though.
Not good enough - for regex, you have to define the requirements exactly. Only double quotes around words that precede two double quotes ?; double quotes around words anywhere ?; what's a word in this context ?.
Regex can be constructed to do any of the above, but likely not (simply) in one execution - sed supports multiple -e in one command invocation though.
Yes, and additionally you cannot specify an regexp for exclusion (or at least not in the same step). Actually there is no such thing (regexp for exclusion), you need to look for the required regexp and skip that line (where it was found).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.