The sed command replaces the sed stream editor with the line break, which is the receiver for processing text content in shell. The sed command reads a line of text from the text stream to the mode space for corresponding command, or script processing, so it will be a bit special when processing line breaks. The following command can be correctly executed: 1 echo & quot;... sed command to replace the line break sed flow editor is the receiver for processing text content in shell. The sed command reads a line of text from the text stream to the mode space for corresponding command, or script processing, so it will be a bit special when processing line breaks. The following command can be correctly executed: 1 echo "a, B, c, d" | sed's/,/\ n/g', but if I want to restore it back, the following command does not work: 1 echo "a, B, c, d" | sed's/,/\ n/g' | sed's/\ n /, /g' is related to sed's row processing method. when sed reads a row, it first removes the line feed and adds it after processing, therefore, you cannot use the above command to replace the line break. you must use other commands in sed. You can use the tr command for the above recovery: 1 echo "a, B, c, d" | sed's /, /\ n/g' | tr-t '\ N''. Below are some of the usage found on the internet. the practical results are different, only one method is completely feasible. 1sed ': label; N; s/\ n/:/; B label 'filename1sed': label; N; s/\ n /:/; the two commands above t label 'filename' can replace all line breaks in the file with specified strings, such as the colon in the command. Command explanation: label. this is a label used for jump processing. The name can be taken as a label. The next B label is the jump command N; N is a processing command of sed. it appends the next row in the text stream to the mode space for merging. Therefore, the line break is visible. s/\ n/:/; s is the replacement command of sed, replace the line break with the jump command of colon B label or t label B/t is sed, to jump to the specified tag, the tag jump and the N append command implement the uninterrupted loading of each line into the processing space, so that every line break is not missed. if there is no tag, only one line break can be replaced for each two rows. Comparison: 1 $ echo "a, B, c, d" | sed's /, /\ n/g' | sed ': x; N; s/\ n/,/; B x '2a, B, c, d3 $ echo "a, B, c, d "| sed's/,/\ n/g' | sed 'n'; s/\ N/,/'4a, b5c, d. the following command is not capable of line breaks.. In fact, the $ symbol represents the last line in the text stream in sed. I don't quite understand the following processing result. 1 $ echo "a, B, c, d" | sed's/,/\ n/g' | sed's/$/,/'2a, 3b, 4c, 5d, PS: n commands and ~ In sed ~ The address indicates 1sed '8, 80 {n; d} 'filenamen indicates to read the next row in the text stream to the mode space (N is append), and sed still processes only one row. The preceding command reads 8th/11 rows at a time starting from 9/10 rows (inclusive), and then reads 11 Rows. then, execute the d command to delete the 11th rows in the processing space, then, start from 12 rows, read 13/14/15, delete 15 rows, and so on until 80th rows. 1sed '11 ~ 4d 'filename this command implements the same function as the previous command. The only difference is that it does not specify the end line until the end of the file.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service