You can do that very easily using perl6
:
perl6 -pe 's:g/<:punct-[-@_%]>+//' file
<:punct-[-@_%]>
will match any punctuation character, except -@_%
.
:g
is the global
switch (like s/foo/bar/g
in perl5 or sed)
To be allow comparison between answers (and also because I'm lazy), I'll reuse @RomanPerekhrest's sample input:
.!?,'/\"()[]^* @-$%
.!?,'/\"()[]^* @ sdfsd %
as,,d//asd a?sd %% --@_ _asdasdad$
sdfsdf %''%!% 2 + 2 = (?)
So this line:
perl6 -pe 's:g/<:punct-[-@_%]+[^]>+//' file
Gives:
^ @-$%
^ @ sdfsd %
asdasd asd %% --@_ _asdasdad$
sdfsdf %%% 2 + 2 =
Note that it differs from the answer given by @RomanPerekhrest. If you consider that ^
, =
or +
should be included too, then you can use the following line:
perl6 -pe 's:g/<:punct-[-@_%]+[^+=]>+//' file
The output will be the same:
@-$%
@ sdfsd %
asdasd asd %% --@_ _asdasdad$
sdfsdf %%% 2 2
[...]
and keep in mind that]
has to be first and-
last in that list e.g.sed 's/[].!?,'\''/\\"()[^*]//g'
– don_crissti Sep 10 '17 at 20:12