Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to delete the last two lines of a file in mysql

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article shows you how to delete the last two lines of a file in mysql, which is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Create a new file and display the line number in the file to facilitate subsequent execution to view the results

Cat-b / etc/passwd > a.txt

Cat / a.txt

.. Omit N lines

34dhcpd:x:177:177:DHCP server:/:/sbin/nologin

35lisi:x:500:500::/home/lisi:/bin/bash

36zhangsan:x:501:501::/home/zhangsan:/bin/bash

37mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash

38named:x:25:25:Named:/var/named:/sbin/nologin

39qemu:x:107:107:qemu user:/:/sbin/nologin

40radvd:x:75:75:radvd user:/:/sbin/nologin

Write a script

[root@svr5 Desktop] # vim / shell/del.sh

#! / bin/bash

Lines= `cat $1 | wc-l`

Sline= `expr $lines-1`

Sed-I''$sline',+1d' $1

Execute script

[root@svr5 Desktop] # sh / shell/del.sh / a.txt

View the execution result

[root@svr5 Desktop] # cat / a.txt

. Omit N lines

35lisi:x:500:500::/home/lisi:/bin/bash

36zhangsan:x:501:501::/home/zhangsan:/bin/bash

37mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash

38named:x:25:25:Named:/var/named:/sbin/nologin

The above is how to delete the last two lines of a file in mysql. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report