Linux uses the sed command to add a string method

  

There are many ways to add a Linux string. One is to add a string at the beginning and end of the text. This article will introduce Linux's method of adding strings using the sed command.

command beginning or end of a row of characters by adding sed command are the following:

text processing is assumed test.file

in each row Add characters to the header, such as “HEAD”, the command is as follows:

sed ‘s/^/HEAD&/g’ test.file

Add characters at the end of each line. such & ldquo; TAIL & rdquo ;, the following commands:

sed & lsquo; s /$ /& TAIL /g & rsquo; test.file

FIG results are as follows:

A few notes:

1.“^” stands at the beginning of the line, “$” stands for the end of the line

2.‘s/$/&TAIL/g’ The character g in the middle represents the replacement of all characters appearing in each line. If you want to add it at a specific character, g is useful. Otherwise, only the first one of each line will be replaced, and you will not find it later.

:

Previous 12 Next total 2

Copyright © Windows knowledge All Rights Reserved