Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

[SOLVED] - VI Syntax cut wrong position

New to Debian (Or Linux in general)? Ask your questions here!
Post Reply
Message
Author
mauric
Posts: 43
Joined: 2017-07-25 08:50

[SOLVED] - VI Syntax cut wrong position

#1 Post by mauric »

Hello
i have little troube with VI i need to format me IP list file.
if i run this command the result arn't not like what i need.

#vi -b -c '%s/^.\{22}/' -c '%s/$/REJECT/' -c wq /etc/fail2ban/nixspam-ip.dump

Result:
166.151.58.56 ^MREJECT
200.119.204.58 ^MREJECT
but i Need
166.151.58.56 REJECT^M
200.119.204.58 REJECT^M
and to delete this lines complet that beginn with "..." without any whitespace?

:sort
:g/^\...*/d

-> this Version will delete me a lot of more that i explain :-/

223.247.13.30 ^MREJECT
203.74.203.49 ^MREJECT
...505ce8c5f808cbae8af056b1956f8487 ^MREJECT
223.30.192.54 ^MREJECT
222.239.91.54 ^MREJECT
166.151.58.56 ^MREJECT
200.119.204.58 ^MREJECT
...6edf7e6e319cf3365eb39c78806ab5bb ^MREJECT
113.190.254.74 ^MREJECT
...77407d66817542a7b384e5927df10d45 ^MREJECT

thanks for any possible help!
Mauri
Last edited by mauric on 2018-02-26 20:45, edited 1 time in total.

mauric
Posts: 43
Joined: 2017-07-25 08:50

Re: VI Syntax cut wrong position

#2 Post by mauric »

frendly will ask if here no answer are possible?

Please dont write all Together
Thanks

User avatar
Bloom
df -h | grep > 90TiB
df -h | grep > 90TiB
Posts: 504
Joined: 2017-11-11 12:23
Been thanked: 26 times

Re: VI Syntax cut wrong position

#3 Post by Bloom »

Your regular expression is wrong, I think.

-c '%s/$/REJECT/

should be

-c '%s/\rREJECT$/REJECT\r/'

To delete all lines beginning with '...', I think you need to escape all the dots:

:g/^\.\.\.*/d

mauric
Posts: 43
Joined: 2017-07-25 08:50

Re: VI Syntax cut wrong position

#4 Post by mauric »

Thanks Bloom

yes on this place also i was one week ago......

vi -b -c '%s/\rREJECT/REJECT\r/' -c wq /etc/fail2ban/ipdownload/_ni
/etc/fail2ban/ipdownload# cat _ni | more
185.207.10.114
175.14.115.119
Please i need this version:
95.86.46.213 REJECT^M
95.86.56.198 REJECT^M
i see in VI
:set list
2018-02-25T09:29+0100 46.160.182.99^I$
2018-02-25T09:28+0100 212.18.43.95^I$
2018-02-25T09:28+0100 ...43b679bd42d9944814757b557b4ae405^I$
2018-02-25T09:28+0100 62.149.116.5^I$
2018-02-25T09:28+0100 41.212.28.33^I$
2018-02-25T09:28+0100 167.61.68.33^I$

but what are mean ^I$
and how i can delete this

no way
vi -b -c '%s/^I/g' -c wq /etc/fail2ban/ipdownload/_ni
vi -b -c '%s/^I$/g' -c wq /etc/fail2ban/ipdownload/_ni

thanks







yes to delete this Syntax from you delete only the entrys that beginn with "..."
thanks alot for your help!

mauric
Posts: 43
Joined: 2017-07-25 08:50

Re: VI Syntax cut wrong position

#5 Post by mauric »

Hello Mauri

vi -b -c 'set ff=unix' -c '%s/^.\{22}/' -c 'g/^\.\.\.*/d' -c '%s/\r//' -c '%s/$/\tREJECT^M/g' -c wq /etc/fail2ban/ipdownload/_ni
Cat _ni = Result, Perfekt!
146.0.246.4 REJECT^M
146.0.246.7 REJECT^M
185.53.131.122 REJECT^M
thanks
Mauri

Post Reply