1. How can I print out a line with a user UID greater than 500 in/etc/passwd?Awk-f ': ' $ > ' passwd2. What does NR,NF two variables mean in awk? Awk-f ': ' {print $NR} '/etc/passwd will print out what results?NR is the number of rows NF is the number of segmentsPrints the 1th paragraph of the first row, the 2nd paragraph in the second row, the 7th segment of Lin
:
function
Description
Index (string1, string2)
Returns the position of the first occurrence of string2 in string1
Length (String)
Returns the length of a string
Match (STRING,REGEXP)
Returns a string that conforms to the regexp substring
Split (String,array,seperator)
Separates string strings into multiple fields according to the delimiter Seperator, and stores them in an array of arrays
[,seps]):Function: The string represented by FIELDSEP is sliced as a delimiter, and the result of the slice is saved to an array with the array name, and the subscript is starting from 1;Length (String)Function: Returns the length of a given stringSUBSTR (String,start[,length])Function: Take a substring from a string, from start to the starting position as a substring of length;[[email protected] bashtest]# last-n 5 |awk ' {print $ "\ T" $ $} 'Root211
Sed shares the common functions sed and awk. However, we can understand that sed performs operations on text content (text replacement) and awk performs operations on text structure. 1. replace zhc in the filename File with hongchangfirst and put it in filename2.
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.
'/styleText/d' filepath
3. Delete blank rows
sed '/^$/d' filepath
4. Delete rows with unspecified "styles"
sed '/styleText/!d' filepath
5. Output rows matching the "style"
sed -n '/styleText/p' filepath
The command P will display the current data, but because SED will also display non-conforming data rows by default,
Have you ever had to calculate a very large data (hundreds of GB) requirement? Or search inside, or anything else--something that can't be done in parallel. Data experts, I'm talking to you. You may have a 4-core or more core CPU, but our appropriate tools, such as grep, bzip2, WC, awk, sed, and so on, are single-threaded and can only use one CPU core.Borrowing cartoon characters Cartman words, "How can I u
input the numbers:" Read aread bif (($a = = $b)), then echo "a = B" elif (($a > $b)) and then E Cho "a > B" Else echo "A (2) Find Files#!/bin/bashecho "Enter a file name:" Read AIF [-e/home/tach/$a];then echo "The file is exist!" else echo "The file is not exist!" Fi(3) Delete files of size 0#!/bin/bashfor filename in ' ls ' does a=$ (ls-l $filename | awk ' {print $} ') if (a==0), then rm $filename F Id
: delete command"$1": Refers to a command line parameter, indicating that white space or special characters can be used in the file name.
2. replace a string (or matching mode) in a file with another string (or matching mode)Sed-e "s/$ old_pattern/$ new_pattern/g" $ file_nameS: substitution replacement"G", that is, the global flag, used to automatically replace
3. Write log filesEcho "'date' + 'whoam' + $ operation" $ @ ""> $ file_name$ Operation: bef
Combat one: File a006 take out the numbers insideTl_fmt_chg_shm_key=7100;export Tl_fmt_chg_shm_keyTl_msq_shm_key=7200;export Tl_msq_shm_keyTl_txn_srv_shm_key=7300;export Tl_txn_srv_shm_keySed methodSed ' s/\ (. *\) =\ (. *\); \ (. *\)/\2/' a006710072007300awk-f\; ' {print $} ' a006 | Awk-f= ' {print $} '//awk methods There are a lot of things I only use in one simple way710072007300Combat two: List command
conveyor, first print front and then print back# sed ' 1 ' d my_printf.sh//delete first line# sed '/yes/' d my_printf.sh Delete rows containing yes# sed ' 2s/name/myname/g ' my_printf.sh//replace the second row of Name for Myname,g is global, no only replaces the first# sed ' s/s/myname/g ' my_printf.sh//No line numbe
Awk is a programming language dedicated for text processing. yes, it is a programming language. It only serves text processing, so you cannot use it to write system software or scientific computing (of course, it can also do mathematical computing ), it can only be used for text processing. unlike SED, awk has the programming language features, including built-in
of LA, if you want to complete the replacement, you should add the global command G, as follows: SED-N'S/LA/OO/GP'DATAF3 This will change all the found LA to OO. The use of substitution, there are also the following: Sed-N's/la//p'DATAF3 Deletes the first occurrence of LA in each row (the substitution of La into an empty string is deleted). Sed's/^...//'DATAF3 Remove the 3 characters from the beginning of
Use regular expressions and grep, sed, awk (1), grepawk
Some nonsense:
For regular expressions, I have always been confused. I can see some code. The script contains regular expressions, awk, sed, and I am totally confused. I can't remember how to use it at ordinary times, so I won't summarize it. If you are free, Let'
#!/bin/env python#coding: UTF8‘‘‘awk prints the specified number of rowsSED prints the specified number of linesPython prints the specified position, a length stringAwk takes the longest, a long timeSed awk time HalfPython time-consuming basic negligibleWhen you use a script to monitor log files, the location of the last exit is loggedPython is the most efficient.‘‘‘Import OSFrom time Import timeFrom Os.pat
http://www.vaikan.com/use-multiple-cpu-cores-with-your-linux-commands/Have you ever had to calculate a very large data (hundreds of GB) requirement? Or search inside, or anything else--something that can't be done in parallel. Data experts, I'm talking to you. You may have a 4-core or more core CPU, but our appropriate tools, such as grep, bzip2, WC, awk, sed , and so on, are single-threaded, Only one CPU c
|headThe begin {Command} End{command} structure in awk, specifying the operation of the head and tail, different from the general begin END block structureSpecial meta characters in awk: +,? + Match all,? Match a single characterMatch operator: ~,!~//~ match,!~ mismatchHead messages |awk ' $ ~/21:59/' matches 21:59 rows, which is equivalent to the grep feature,
does not end with 90,/90 $ /! Enter {n; B myloop }. N enters the multi-row mode, attaches the next row, and then enters branch B myloop. It judges whether it ends with 90 and reads it repeatedly until it reads the row ending with 90. Next, the read of the mode space is complete. Enter the next command, replace, S/\ N // G? This command converts all linefeeds in the current mode space to null, that is, concatenates them into a row. In this way, we have achieved our goal.
2.
the most recent time)-ctime: +/-n based on the creation time of the file "in the day dimension, span large;-cmin, Minute Dimension"-atiime: +/-based on the access time of the file "IBID.;-amin, Minute Dimension"-mtime: +/-based on the modified time of the file "IBID.;-mmin minute Dimension"-exec cmd {} \;: The Find command executes the shell command given by the parameter to the matching file, noting "{}" and "\;" There are spaces example: 1, find files created within the day of 1 hours before
Here are just the simplest ways to do this.SED implementationOne:Odd line sed-n ' p;n ' fileEven line sed-n ' n;p ' fileThis may be difficult to understand, as an example on the Internet:example, remove even rows from the AAA fileCat AAAThis is 1This is 2This is 3This is 4This is 5Sed-n ' n;p ' AAA//-n means cancel default outputThis is 2This is 4Note: Sed reads
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.