In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces linux how to delete the first few lines of the file, the article is very detailed, has a certain reference value, interested friends must read it!
In linux, you can use the sed command to delete the first few lines of the file, which can be processed and edited in accordance with the instructions of the script, and can be used with regular expressions to achieve the effect of deleting the first few lines of the file. The syntax is "sed-I'1, the first few lines of the file name".
The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
Linux how to delete the first few lines of the file sed-I '1d` file name this is to delete the first line to the nth line
Sed is a stream editor, it is a very good tool in text processing, can be used perfectly with regular expressions, the function is extraordinary. When processing, the currently processed line is stored in a temporary buffer, called "pattern space" (pattern space), and then the contents of the buffer are processed with the sed command, and when the processing is completed, the contents of the buffer are sent to the screen. Then process the next line, which is repeated until the end of the file. The contents of the file have not changed unless you use redirect to store the output.
Sed is mainly used to automatically edit one or more files, can replace, delete, add, select and other specific work, simplify the repeated operation of the file, write conversion procedures, and so on.
Grammar
Sed [- hnV] [- e] [- f] [text file]
Parameter description:
-e or-- expression= processes the input text file with the script specified in the option.
-f or-- file= processes the input text file with the script file specified in the option.
-h or-- help displays help.
-n or-- quiet or-- silent displays only the results after script processing.
-V or-- version displays version information.
Action description:
A: added, a can be followed by strings, and these strings will appear on the new line (the current next line) ~
C: instead, c can be followed by strings, which can replace the lines between N1 and N2!
D: delete, because it is a deletion, so he Dongdong is not usually replaced by d.
I: insert, I can be followed by strings, and these strings will appear on the new line (the current previous line)
P: print, that is, the selected data is printed out. Usually p runs with the parameter sed-n ~
S: replace, you can directly carry out the work of replacement! Usually the action of this s can be matched with the formal representation! For example, 1Magazine 20s Universe, OldCompact newscop g is it!
Examples are as follows
Delete the first lines 1 to 14030000 of send_url_log.txt
Sed-I'1 1403000d' send_url_log.txt and above are all the contents of this article "how to delete the first few lines of a file by linux". Thank you for reading! Hope to share the content to help you, more related knowledge, 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.