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 replace newline characters in files under linux

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to replace the newline characters in the file under linux. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Previously, execute the following command on the linux system: ls file | xargs sed-I's /\ nUniverse G' but found no effect. Baidu later found that sed processes text data on a line-by-line basis. After each line of data is processed, trailing newline... is automatically added at the end of the line

Previously, execute the following command on the linux system:

Ls file | xargs sed-I's /\ nUniverse g'

However, it was found that there was no effect. Baidu later found that sed processes text data by line, and every time it processes a line of data, it automatically adds trailing newline at the end of the line.

If you have to use the sed command, and the newline character that replaces the file text content is empty, then you need to know the branch conditional command of sed, as well as the pattern space mode space and hold space retention space of sed. That is, execute the sed command on two lines in a row, so that the\ nsubstitution of the previous line can be completed.

The final implementation of the command is shown in the following example:

Sed ": a Tantra Nissan /\ nCompact GTX ta" a.txt

N adds the next line to the current hold space mode space for subsequent processing, and finally sed will print the content in the hold space mode space by default. In other words, sed can handle multiple rows of data.

An and ta are used together to realize the jump function. T means test test.

This is the end of this article on "how to replace line breaks in files under linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

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

Development

Wechat

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

12
Report