In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Sed is a text processing tool that relies on regular expressions to read text content, add, delete, and replace data according to specified conditions. It is widely used in shell scripts to complete automated processing tasks.
Sed does not directly modify the source file by default when processing data, but stores the currently processed line in a temporary buffer. All instructions operate in the buffer. After processing is completed, the buffer content is output to the screen by default, and then the next line content is processed. This is repeated until the end of the file. The content of the file itself has not changed.
1. Sed has three main functions:
(1) Reading: sed reads a line from the input stream (file, pipe, standard input) and stores it in a temporary buffer;
(2) Execution: By default, all sed commands are executed sequentially in the pattern space, unless the row address is specified, otherwise the sed command will be executed sequentially on all rows;
(3) Display: After sending the modified content to the output stream and sending the data again, the pattern space will be cleared.
*** Note: By default, all sed commands are executed in schema space, so input files do not change unless redirected storage is used for output.
Second, the Sed command has two formats:
Among them,"parameter" refers to the target file of the operation, and when there are multiple operation objects, the files are separated by commas "and"; while scriptfile refers to the script file, which needs to be specified with "-f" option. When the script file appears before the target file, it means that the input target file is processed through the specified script file.
sed [options] 'action' parameter
sed [options] -f scriptfile parameter
(1) Common sed command options:
-e: indicates that the input text file is processed with a specified command or script;
-f: indicates that the input text file is processed with the specified script file;
-h: Display help;
-n: indicates that only processed results are displayed;
-i: Edit text files directly;
(2) Common operational options:
a: Add, add a line of specified content below the current line;
c: Replace, replaces the selected row with the specified content;
d: Delete, delete the selected row;
i: Insert, insert a specified line above the selected line;
p: Print, if you specify lines at the same time, means print the specified lines; if you do not specify lines, means print everything, usually used with the-n option;
s: replace, replace the specified character;
y: character conversion;
I. Introduction to awk:
In Linux/UNIX systems, awk is a powerful editing tool that reads input text line by line, searches according to specified matching patterns, formats output or filters content that meets the conditions, and can implement quite complex text operations without interaction. It is widely used in Shell scripts to complete various automated configuration tasks.
2. Common usage:
Single quotes enclosed in curly brackets "{}" are used to set processing actions to be performed on data. awk can process the target file directly, or it can process the target file by reading the script with "-f".
Awk treats a line in a text file as a record, and a part (column) of a line as a word (field) in a record. To manipulate these different fields, awk borrows the shell's approach to positional variables and sequentially represents the different fields in a row (record) as $1,$2,$3,... Awk also uses $0 to represent the entire row (record). Different fields are separated by specified characters. The default delimiter for awk is a space. awk allows delimiters to be specified on the command line in the form of the "-F delimiter."
awk [options]'mode or condition {edit command}' file 1 file 2
awk -f script file 1 file 2
1) Special built-in variables (directly available)
FS: Specifies the field separator for each line of text, defaulting to spaces or tabs (tab keys);
NF: Number of fields in the currently processed row;
NR: line number (ordinal) of the currently processed line;
$0: the entire row content of the row currently being processed;
$n: n-th field (n-th column) of the current processing row;
FILENAME: the name of the file being processed;
RS: data record separation, default is\n, that is, each row is a record;
(2) Relational operator: performs the specified action only if the condition is true.
Greater than (>); Less than (=); Less than or equal to (
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.