[SOLVED] - VI Syntax cut wrong position

New to Debian (Or Linux in general)? Ask your questions here!

[SOLVED] - VI Syntax cut wrong position

Postby mauric » 2018-02-24 07:57

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: 28
Joined: 2017-07-25 08:50

Re: VI Syntax cut wrong position

Postby mauric » 2018-02-25 06:20

frendly will ask if here no answer are possible?

Please dont write all Together
Thanks
mauric
 
Posts: 28
Joined: 2017-07-25 08:50

Re: VI Syntax cut wrong position

Postby Bloom » 2018-02-25 07:11

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
User avatar
Bloom
 
Posts: 71
Joined: 2017-11-11 12:23

Re: VI Syntax cut wrong position

Postby mauric » 2018-02-25 07:53

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: 28
Joined: 2017-07-25 08:50

Re: VI Syntax cut wrong position

Postby mauric » 2018-02-25 09:28

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
mauric
 
Posts: 28
Joined: 2017-07-25 08:50


Return to Beginners Questions

Who is online

Users browsing this forum: No registered users and 4 guests

fashionable