Title: SED/awk equivalent code to Unix Commands
From: www.chinaunix.net thank you very much
Equivalent code of SED and Unix commands:
-------------------------------------------------------------------------------cat | sed ':'cat -s | sed '/./
can write multiple lines of code. You can even use awk to write complicated and disturbing functions. However, after all, awk is still a text processing program, usually through pipelines. Removing (unnecessary) the loop definition is a common and convenient method. However, if you are happy, you can also use the following code to do the same thing:
awk '{ if
, $3 }'
(12). Pass the value to awk in the command line
Format:
Awk command variable = input value.
For example:
DF-k | awk '($4 ~ /^ [0-9]/)/{if ($4
(13). awk Array
You do not need to define arrays before using them. Generally, you can use loops to access arrays. Format:
For (element in array) print array [element]
; D.txtThe regular in SED:1: Delete file empty line[[Email protected] ~]$ sed '/^$/d '/etc/passwd >e.txt2: Write a record (line) containing EXT4 in Fstab to a new file[[Email protected] ~]$ sed '/ext4/w newfstab '/etc/fstab======================================================================AwkAWK is a programming language tool for working with textAny
execute the command, here printf is the command of AWK, the $ $ extract file in the second column, $ $ Extract the third column, $ fetch all columns) df-h | awk ' {print $ \ t ' $ "\ t" $6 "\ T"} '(Print three columns, here the print is Awk's command, the system does not have the print command, so it can only be used in awk; the difference with printf is that
/fstab3. Save the odd line of the/etc/fstab file as a/tmp/fstab.3;Solution:sed ' 1~2w/tmp/fstab.3 '/etc/fstab4.echo a file path to the SED command, take out its base name, and further, remove its path name;Answer:1.echo/etc/fstab | Sed-r ' [Email protected]*/([^/]+)/[email Protected]\[email protected] ' base name2.echo/etc/fstab/| Sed-r ' [email protected] ([^/]+
Basic shell programming [3]-common tools awk \ sed \ sort \ uniq \ od, awkuniqAwk
Awk is a very useful thing. It is widely used in the presentation and processing of linux system analysis results. You can also use pipelines, input | awk ''| output1. first, you need to know the form of
Tags: use of sed punctuation replace control character command [] simplify code screenThe grep sed for the Linux Text Processing tool In the Linux system, there is a philosophical thought: Under the Linux system, everything is file.This shows how important the tool for text processing is, and we often use text processing tools such as
command is only placed in a file, and the file must be! /Bin/awk-F, because this will make this file self-explanatory. Otherwise, it will not work. For ease of separation, it is best to include a file extension. awk. After writing the file, use chmod U + X to make the file executable.
//////////////////////////////////////// //////////////////////////////////////// ////////////////////////////////////////
Use sed and awk to obtain the latest DataNode information of the cluster, awkdatanode
Due to the poor remote desktop, when the cluster has missing block, you cannot log on to the Remote Desktop to view the nodes that have crashed the DataNode process due to restart. At the same time, it is inconvenient to simply use the command hdfs dfsadmin-report to view the information, and there is too much information.
)Sed ' s#[^0-9a-z]# #g ' 123Swap the first and last words in the test.txt positionSed-r ' s# (^.*) (:. *:.*:.*:.*:.*:.*/.*/) (. *$) #\3\2\1#g ' Test.txtBash:x:0:0:root:/root:/bin/root (last word with first swap)Sed-r ' s# (^.*) (:. *:.*:.*:.*:.*:.*) (/.*/.*$) #\3\2\1#g ' Test.txt/bin/bash:x:0:0:root:/root:root (the last shell and the first word exchange)Sed ' s#\
Sed and awk
Background
When designing a script, you may need to modify the script, such as deleting or replacing some keywords. This method of dynamically modifying files during script execution is called Stream editing. A tool with stream editing capabilities is called stream editor ). Sed is a leader in this field and can complement bash's shortcomings. In addi
When I modified the spec configuration file packaged by rpm today, I encountered a problem:You need to set around 100Source codeThe version number in the release row in the spec configuration file is replaced with the macro variable % {_ release }..
If you want to manually modify it, you need to modify it more than 100 times, but using the SED and grep commands is simple:
Sed Structure Analysis
Sed/awk provides many tutorials, most of which are examples of teaching materials, or grammar textbooks.
After learning SED and awk, the results are learned, which is easy to confuse and the syntax is easy to confuse.
This article mainly explains the s
What are regular expressionsA method of handling characters that can be used to handle regular expression strings as long as the command tool (e.g. grep, sed, awk, and so on) supports this method. With the help of special characters, we can easily find, delete, replace the specific string of the command program.UseInformation filtering, information matching, acce
Basic use of Awk and SedYou can call sed and awk in the same way. The command line is as follows:Command [options] script filenameLike almost all unlx programs, sed and awk can get input from standard input and send output to standard output. If filename is specified, the in
\+\)/[--\1--] [\2]/g ' list[--line--] [200]Line3 100Line4 100Line5 700Line5 800Line6 50Line7 350multiple sed combinations,[Email protected]:~# sed ' s/\ (\w\+\) 2\ (\w\+\)/[--\1--] [\2]/g ' list | sed ' s/line7/tttt/g '[--line--] [200]Line3 100Line4 100Line5 700Line5 800Line6 50TTTT 350AwkAwk is so powerful that I'm not listed here for space reasons, and I can se
a/tmp/fstab.3;650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;margin:0px;padding-right:0px; "border=" 0 "alt=" image "src=" Http://s3.51cto.com/wyfs02/M00/73/9D/wKiom1YCOMajYsnnAABloVsv4Wg148.jpg "height=" 123 "/>(4) Echo a file path to the SED command, take out its base name, and further, take out its path name;650) this.width=650;
encounter the situation of changing a variable name to another variable name. If this variable is a local variable, VI is sufficient, however, if a global variable is used in many filesAn unwise choice. A simple shell command is provided here to modify the specified string in all files at a time:Grep "ABC" *-r | awk-F: '{print $1}' | sort | uniq | xargs sed-I's/ABC/ABCDE/G' From: http://blog.zol.com.cn/13
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.