AWK Introduction
9.1 Three ways to call awk
:
1. Command line method:
awk [-F filed-separator] 'commands' input-files
-F Specify the separator (default is space or tab)
commands awk The command
input-files is the file to be processed
2. Insert all the awk commands into a file and make the awk program executable, then use the awk command interpreter as the first line of the script so that you can call it by typing the script name
3 . Insert all awk commands into a single file, and then call:
awk -f awk-script-file input-files
-f Specify the calling script name
input-files File to be processed
9.2 awk script
in the command When awk is called, an awk script consists of various operations and modes.
awk reads one record or line at a time and separates the specified fields using the specified delimiter. When a new line appears, the awk command learns that the entire record has been read, and then starts the read command on the next record. This reading process will continue until the end of the file or the file no longer exists.
9.2.1 Patterns and Actions
Any awk statement consists of patterns and actions. The mode part determines when the action statement is triggered and the triggering conditions. Processing is the operations performed on data. If the mode part is omitted, the action will remain executed at all times.
The pattern can be any conditional statement, compound statement or regular expression, including two special fields BEGIN and END. Use the BEGIN statement to set the count and printhead. The BEGIN statement is used before any text browsing action, after which the text browsing action starts executing based on the input file. The END statement is used to print out the total number of texts and the end status flag after awk completes the text browsing action. If you don't specify a pattern, awk always matches.
The actual action is specified within curly brackets {}. Most of the actions are for printing, but there is also some longer code such as if and loop statements and loop exit structures. If no action is specified, awk will print out all browsed records.
9.2.2 Domains and records
When awk is executed, its browsing domain is marked as $1, $2...$n. This method is called domain identification. When you need to specify multiple domains, use commas to separate them. For example, $1, $3 specifies the first domain and the third domain. If you want to specify all domains, you can use $0.
Use the print command to perform printing operations. This is an awk command and needs to be enclosed in {}.
1. Extract domain
Example: There is a grade.txt file with the following content:
$ cat grade.txt
M.Tansley 05/99 48311 Green 8 40 44
J.Lulu 06/99 48317 Green 9 24 26
P.Bunny 02/99 48 Yellow 12 35 28
J.Troll 07/99 4842 Brown-3 12 26 26
L.Tansley 05/99 4712 Brwon-2 12 30 28
This text file has 7 fields, separated by spaces As domain separator
2. Save awk output
Two ways to save awk output results:
Redirect to file: (no screen display)
$ awk '{print $0}' grade.txt >wow
Use pipe to Pass the output result to tee: (display result on screen)
$ awk '{print $0}' grade.txt|tee woww
3. Use standard input
Several methods:
$ belts.awk grade.txt
$ belts.awk < grade.txt
4. Print all records
$ awk '{print $0}' grade.txt
5. Print individual records
Only print $1 and $4:
$ awk '{print $1,$4}' grade.txt
6. Custom format printing
You can add comments above $1 and $4, Name and Belt:
$ awk 'BEGIN {print "NamettBeltn------------------ ------"} {print $1"t"$4}' grade.txt
Add a closing comment at the end:
$ awk 'BEGIN {print "NamettBeltn------------- ------------"} {print $1"t"$4} END {print "------------------------ -nEnd of report"}' grade.txt
7. awk error message prompt
When you encounter an awk error, you can search accordingly:
• Make sure the entire awk command is enclosed in single quotes
• Make sure all quotes in the command appear in pairs
• Make sure to surround action statements with braces {} and conditional statements with braces ()
• You may have forgotten to use braces {}
8. awk keyboard input
If no input file is given, awk gets the input from the keyboard, press end input when finished
9.2.3 Metacharacters
^ $ . [ ] | ( ) * + ?
where + and ? are only applicable to awk and not to grep or sed:
+ Match one or more preceding single characters
? Match 0 or one preceding single character
Example:
/XY+Z/ Match Xyz, xyyyyz
/xy? Z/matching xyz, xz
9.2.4 condition operator
operator description
& lt; less than
& lt; = less than equal
== equal
! = Not equal to
& gt; = Greater than equal to 匹 ~ match regular expression
! ~ Not match regular expression
1. Matching
use ~ follow the regular expression can be matched, or if the conditions need to be used () All situations for brown belt students (print out the row where $4 matches Brown)
$ awk '{if ($4~/Brown/) print $0}' grade.txt
or
$ awk '$0 ~ /Brown/' grade.txt
2. Exact match
Use == and enclose the condition in double quotes to match the condition exactly
Example:
$ awk '{if ($3 == "48") print $0}' grade.txt
3. No match
Use !~Follows the regular expression mismatch field
Example:
Query all students who are not brown belts (print out the row where $4 does not match Brown)
$ awk '{if ($4!~/Brown/) print $0}' grade.txt
or
$ awk '$0 !~ /Brown/' grade.txt
4. Comparison
Since the usage methods of several comparison symbols are the same, let’s just give an example:
$ awk '{if ($6 < $7) print $1" try better at the next comp"}' grade.txt
5. Various matches
match Green or green:
$ awk '/[Gg]reen/' grade.txt
match $1's The four characters are a:
$ awk '$1 ~ /^...a/' grade.txt
matches Yellow or Brown:
$ awk '$4 ~ /Yellow|Brown/' grade.txt
matches those starting with J Line:
$ awk '$0 ~ /^J/' grade.txt
6. Compound expression
Compound patterns or compound operators are used to form complex logical operations. Compound expressions are patterns that interact with each other through the use of compound operators. The combined expression
&& AND: Both sides of the symbol must be true at the same time
|| OR: At least one of both sides of the symbol is true
! : Non-inversion
Example:
$ awk '{if ($1 == "P.Bunny" && $4 == "Yellow") print $0}' grade.txt
$ awk '{if ($4 == "Yellow" || $4 ~ /Brown/) print $0}' grade.txt
9.2.5 awk built-in variables
awk has many built-in variables for setting environment information. Commonly used ones are:
ARGC . The number of rows of records processed in the file
FS Set the field delimiter, equivalent to -F
NF The number of columns in the field
NR The total number of rows of records processed
OFS Set the field delimiter of the output field
RS/ORS Newline character
ARGC support The number of parameters passed into the awk script on the command line. ARGV is the parameter arrangement array of ARGC, where each element is represented as ARGV[n], n is the command line parameter you wish to access. ENVIRON supports environment variables set by the system. To access individual variables, use the actual variable name, such as ENVIRON[" EDITOR”]=”Vi”
FILENAME is the file name of the file currently operated by the awk script
FNR is the number of record lines in the file currently operated by awk, and its value is always less than or equal to NR. If the script is accessing multiple files, this variable will be reset for each new input file
FS is used to set the domain separator, the same as -F on the command line, and the default is a space. For example: Use colon as the separator FS=":"
NF is the number of record fields (number of columns), which is set after the record is read. $NF is often used to specify the last column
OFS specifies the field delimiter for output records, which defaults to spaces. For example: use - as the delimiter to output FS="-"
ORS and RS are both output record delimiters, the default is new line (n)
Example:
View the number of records in the file:
$ awk 'END {print NR }' grade.txt
Print all records, their line numbers and the total number of fields, and at the end print out the file name of the read file:
$ awk '{print NF,NR,$0} END {print FILENAME}' grade .txt
Contains at least one record and contains Brown:
$ awk '{if (NR > 0 && $4 ~ /Brown/) print $0}' grade.txt
A powerful feature of NF is to return the value of the variable $PWD Pass in awk and display its directory:
$ echo $PWD | awk -F/ '{print $NF}'
Display the file name:
$ echo "/usr/apache/conf/httpd.conf" | awk -F/ '{print $NF}'
9.2.6 awk operator
The basic expressions of the awk operator can be divided into numeric, string, variable fields and array elements
= += -= *= /= %= ^= Assignment operator
? Conditional expression operator
|| && ! Union, AND, NOT
~ !~ Matching operator ( Matching or not matching)
< <= == != > >= Operators
+ - * / % ^ Arithmetic operator
++ -- using using using use using using through through out through out through through out through off ‐ through off ‐ ‐‐ ‐ and ‐ to d. or relationship operations are easier to understand. The general variable name setting method is name=$n, where name is the name of the domain variable called, and n is the actual domain number. Separate multiple domain name settings with a semicolon; (please note the use of ; below)
$ awk '{name = $1;belts = $4; if (belts ~ /Yellow/) print name" is belt "belts}' grade .txt
2. Field value comparison operations
There are two ways to test whether one numerical field is less than another numerical field:
1) Assign a value to the variable name in BEGIN
2) Use the actual value in the relational operator
Usually in BEGIN Partial assignment is very beneficial and can save a lot of trouble when making changes to awk expressions. You must use parentheses when using relational operations. Example:
Query all students who scored less than 27 points in all competitions:
$ awk '{if ($6 < 27) print $0}' grade.txt
or
$ awk 'BEGIN {BASELINE = "27"} {if ($6 < BASELINE) print $0}' grade.txt
3. Modify the value of a numeric field
When modifying any field in awk, it is important to remember that the actual input file cannot be modified, the modification is only saved A copy of awk in the cache. Awk will reflect the modification traces in the variable NR or NF. To modify the numerical field, simply reassign the field identifier to a new value. Example:
$ awk '{if ($1 == "M.Tansley") $6 = $6 - 1; print $1,$6,$7}' grade.txt
4. Modify the text field
Modifying the text field means reassigning it , assigned to a new string. Remember to use double quotes for strings and parentheses around the entire syntax. Example:
$ awk '{if ($1 == "J.Troll") ($1 = "J.L.Troll"); print $1}' grade.txt
5. Only display modification records
If the file is large, the modification record There are many, so you need to only view the modified parts. Using braces {} after the pattern will print only the modified parts. Obtain the pattern and perform operations based on the pattern results. Example: (note the position of the curly brackets)
$ awk '{if ($1 == "J.Troll") {$1 = "J.L.Troll"; print $1}}' grade.txt
6. Create a new output field
When working with data in awk, it is a good practice to create new fields when performing calculations based on each field. Creating a new domain requires assigning the new domain identifier to another domain. Example:
Create a new domain 8 in grade.txt and save the difference between the domain's current level score and the domain's highest level score:
$ awk 'BEGIN {print "NametDifference"} {if ($6 < $7) {$8 = $7 - $6; print $1,$8}}' grade.txt
Or give the variable name that is easy to understand:
$ awk 'BEGIN {print "NametDifference"} {if ($6 < $7) {diff = $7 - $6; print $1, diff}}' grade.txt
7. Increasing column values
Use the symbol += to increase the number of columns or perform statistics on running results. Assign the value of the variable field on the right side of the symbol to the left side.
Example:
Print out the total scores of all students (sum the $6 in the entire file, total is the variable name):
$ awk '(total += $6); END {print "Club student total points: "total}' grade.txt
If the file is large and you only want to print the result part instead of all records, just add braces {} outside the statement:
$ awk '{(total += $6)}; END {print "Club student total points: "total}' grade.txt
View the size and sum of all files in the current directory (excluding subdirectories):
$ ls -l|awk '/^[^d]/ {print $9"t"$5} {total += $5 } END {print "total Bytes: "total}'
9.2.9 Built-in string functions
awk has many powerful string functions:
gsub(r,s,t) Use string s in the entire string t Replace all strings that satisfy the regular expression r (if t is not specified, it defaults to $0)
index(s,t) Returns the position where the string t appears for the first time in the string s (if it does not exist, it is 0)
length(s) Returns the length of the s string (if s is not specified, it defaults to $0)
match(s,r) Returns the position of the first string that satisfies the regular expression r in the s string (if there is no match is 0)
split(s,a,sep) Use sep to separate the string s into the elements of the array a, and return the number of array elements (if no separator is specified, the default is the same usage as FS)
sprint("fmt ",exp) Use printf formatting instructions to format the expression exp
sub(r,s,t) Replace the first string that satisfies the regular expression r with the s string in the string t and return 1 If successful, otherwise it returns 0 (if t is not specified, it defaults to $0)
substr(s,p,n) Returns a string of length n starting from position p in string s (if n is not specified, returns starting from position p All strings starting with)
tolower(s) Converts all uppercase letters in string s to lowercase, returns the converted string
toupper(s) Converts all lowercase letters in string s to uppercase, returns the conversion The resulting string
1. gsub(r,s,t)
Replace all strings that satisfy the regular expression r with string s in the entire string t (if t is not specified, it defaults to $0):
$ awk 'gsub(/4842/,4899) {print $0}' grade.txt
or
$ awk '{if (gsub(/4842/,4899)) print $0}' grade.txt
2. index(s,t )
Returns the position of the first occurrence of string t in string s (0 if it does not exist). The string must be enclosed in double quotes:
$ awk 'BEGIN {print index("Benny","ny")}' grade.txt
3. length(s)
returns the length of the s string (if not If s is specified, it defaults to $0):
$ awk '$1 == "J.Troll" {print length($1)" "$1}' grade.txt
$ awk 'BEGIN {print length("Kevin is a good boy. ")}'
4. Match(s,r)
Returns the position of the first string that satisfies the regular expression r in the s string:
$ awk 'BEGIN {print match("ANCD",/d/ )}' (return 0)
$ awk '$1=="J.Lulu" {print match($1,/u/)}' grade.txt (return the position of the first u in J.Lulu: 3)
5. split(s,a,sep)
Use sep to separate the string s into the elements of the array a, and return the number of array elements:
$ awk 'BEGIN {print split("123#456#789",array, "#")}'
returns 3. The elements of the array array are:
array[1]="123"
array[2]="456"
array[3]="789"
6. sub(r ,s,t)
Replace the first string that satisfies the regular expression r with the s string in the string t, returning 1 if successful, otherwise returning 0 (if t is not specified, it defaults to $0):
$ awk '$1 == "J.Troll" {if (sub(/26/,"29")) print}' grade.txt
7. substr(s,p,n)
Returns the string s starting with p position A string of length n (if n is not specified, all strings starting from position p are returned):
$ awk '$1 == "L.Tansley" {print substr($1,1,5)}' grade.txt (Return L.Tan)
If the given length value n is greater than the string length, awk will return all characters from the starting position:
$ awk '$1 == "L.Tansley" {print substr($1,3,15 )}' grade.txt (return to Tansley)
If n is not specified, awk will return all characters from the starting position:
$ awk '{print substr($1,3)}' grade.txt
Define characters in the BEGIN part String, return the extracted characters in the END part:
$ awk 'BEGIN {STR="Kevin is a good boy."} END {print substr(STR,12,8)}' grade.txt
8. From the shell awk passes in the string
$ echo "Stand-by"|awk '{print length($0)}'
Set the file name to a variable, take the file name:
$ STR="grade.txt"
$ echo $STR|awk '{print substr($STR,1,5)}'
Get the file name suffix:
$ STR="grade.txt"
$ echo $STR|awk '{print substr($STR, 7) }'
9.2.10 awk output function printf
awk provides the function printf, which has several different formatted output functions. Each printf function (control format character) starts with a % sign and ends with a character that determines the conversion. The transformation contains three modifiers. R grammar: inPrintf "Format Control Character", Parameter
AWK Printf Depending Form
-Step of the Left 对 Width domain, use 0 to indicate the maximum string length of.pruc, or the number of digits on the right of the small number
awk printf format
%c ASCII character
%d Integer
%e Floating point (scientific notation)
%f Floating point
%g awk decides which floating point conversion (e or f) to use
%o Octal number
%s String
%x Hexadecimal number
Example:
Character conversion:
$ awk 'BEGIN {printf "%cn",65}' grade.txt
Formatted output:
Print all student names and Serial number, the name is required to be left aligned, 15 characters in length, followed by the serial number:
$ awk '{printf "%-15s %sn",$1,$3}' grade.txt
Add comments:
$ awk 'BEGIN { print "NamettNumber"} {printf "%-15s %sn",$1,$3}' grade.txt
9.2.11 Passing value to a line of awk command
Pass the value into the awk variable before awk is executed. You need to put the variable in Under the command line, the format is:
awk command variable = input file value
Example:
$ awk '{if ($5 < AGE) print $0}' AGE=10 grade.txt
Query partitions with free space less than 36000M:
$ df -m|awk '($4 ~ /^[0-9]/) {if ($4 < LIMIT) print $6"t"$4}' LIMIT=36000
awk also allows environment variables to be passed in. Example:
Query which port the current user is logged in on:
$ who|awk '{if ($1 == user) print $1" you are connected to "$2}' user=$LOGNAME
9.2.12 awk script file
can be The awk script writes to a file and then executes it. The advantage of using awk script is that you don't need to re-enter it every time you use it, and you can add comments for easier understanding. Take an awk script as an example:
#!/bin/awk -f
# all comment lines must start with a hash '#'
# name: student_total.awk
# to call: student_total.awk grade.txt
# prints total and average of club student points
# print a header first
BEGIN{
print "StudentttDatetNumbertGradetAgetPointstMax"
print "NamettJoinedttttGainedtPoint Available"
print "==================== ================================================== ==="
}
# let's add the scores of points gained
(total += $6)
# finished processing now let's print the total and average point
END {
print "Club Student Total points: " total
print "Average Club Student points: " total/NR
}
The first line is #!/bin/awk -f. This line is very important. Without it, the script will not be executed because it tells the script the location of awk in the system. By separating the commands, the readability of the script is improved, and comments can be added between the commands.
Type the file name after the script file when executing, but you need to grant executable permissions first.
9.2.13 Using FS variables in awk
When using awk scripts, setting FS variables is in the BEGIN section. If not, awk doesn't know what the domain separator is.
Script example: (This script extracts the first and fifth fields from /etc/passwd)
#!/bin/awk -f
# to call: passwd.awk /etc/passwd
# print out the first and fifth fields
BEGIN {
FS=":"}
{print $1,"t",$5}
9.2.14 Passing values to the awk script
Passing values to the awk script is roughly the same as passing values to the awk command line, and the format :
awk_script var=value input_file
Example:
#!/bin/awk -f
# name: age.awk
# to call: age.awk AGE=n grade.txt
# prints ages that are lower than the age supplied on the command line
{if ($5 < AGE)
print $0}
Execution method: (don’t forget to give executable permission first)
$ ./age.awk AGE=10 grade.txt
You can also use pipelines The command passes the result of the command to the awk script, such as
$ cat grade.txt |./ student_total.awk
9.2.15 awk array
The array does not need to be defined before use, nor does it need to specify the number of array elements. Loops are often used to access arrays. The following is the basic structure of a loop type:
for (element in array) print array[element]
Example: (the string 123#456#789 mentioned earlier)
#!/ bin/awk -f
# name: arraytest.awk
# prints out an array
BEGIN {
record="123#456#789";
split(record,array,"#")
}
END {
for (i in array) {
print array[i]
}
}
使用/dev/null作为输入运行脚本:
$ ./arraytest.awk /dev/null
从指定文本里找出匹配条件的项及其出现的次数
#!/bin/awk -f
# name: count.awk
# to call: count.awk grade2.txt
# loops through the grade2.txt file and counts how many belts we have in(yellow, orange, red)
# also count how many adults and juniors we have
# start of BEGIN
# set FS and load the arrays with our values
BEGIN {FS="#"
# load the belt colours we are interested in only
belt["Yellow"]
belt["Orange"]
belt["Red"]
# end of BEGIN
# load the student type
student["Junior"]
student["Senior"]
}
# loop thru array that holds the belt colours against field-1
# if we have a match, keep a running total
{for (colour in belt)
{if ($1 == colour)
belt[colour]++}}
# loop thru array that holds the student type against
# field-2 if we have a match, keep a running total
{for (senior_or_junior in student)
{if ($2 == senior_or_junior)
student[senior_or_junior]++}}
# finished processing so print out the matches..for each array
END {for (colour in belt) print "The club has", belt[colour], colour, "Belts"
for (senior_or_junior in student) print "The club has", student[senior_or_junior], senior_or_junior, "students"}
BEGIN部分设置域分隔符为#,初始化两个数组的内容元素。然后处理文件,先给数组命名为colour,使用循环语句比对$1是否等于数组元素之一(Yellow、Orange或Red),如果匹配,依照匹配元素将运行总数保存进数组。同样的方法处理数组senior_or_junior。END部分打印浏览结果,对每一个数组使用循环语句并打印
收集awk的一些技巧方案
awk [opion] 'awk_script' input_file1 [input_file2 ...] awk的常用选项option有:
① -F fs : 使用fs作为输入记录的字段分隔符,如果省略该选项,wak使用环境变量IFS的值。
② -f filename : 从文件filename中读取awk_script。
③ -v var=value : 为awk_script设置变量。
1、删除重复的行
#awk '!a[]++'
2、将数据文件中的每个词的第一个字母变成大写
dingyi@backup:~$ cat test
linux is long live!!!
i am a cuer
dingyi@backup:~$ awk ',1,1); sub(/^./,toupper(first),); print }' test
Linux is long live!!!
I am a cuer
awk 请教
下面是文件一,文件二
$cat file1
00001 20
00002 31
00003 04
00004 56
00005 94
00006 73
00007 25
00008 86
00009 19
00010 52
$cat file2
00001 20
00007 28
00002 32
00004 56
00010 52
怎样的shell才能使file1、file2两个文件的$2不同的话,取出全局$0?
注意:比较两个文件的$2的时候,一定要第一列相同的情况下才比较
请大虾执教
li2002 2003-9-11 08:57
awk Ask for help
Isn’t it just to find out the different lines?
cat file1 file2|sort |uniq -u
deathcult 2003-9-11 09:15
awk Ask for help
paste file1 file2|awk '{if(($1==$3)&&($2!=$4))print$0}'
bjgirl 2003-9-11 09:38
awk Please advise
[code]
# !/bin/ksh
sort -n file1>nf
sort -n file2>mf
paste nf mf|awk '$1=$3 {print}'|awk '$2!=$4 {print}'
rm nf mf
result :
00002 31 00002 32
00004 04 00004 56
00007 56 00007 28
00010 94 00010 52
[/code]
killua 2003-9-11 10:05
awk Ask for advice
Go back to the first floor, I am learning awk recently La, and the value you get is
00002 31
00002 32
00003 04
00005 94
00006 73
00007 25
00007 28
00008 86
00009 19
0 0010 52
00010 52
And what I want is
00002 31 32
00007 25 28
There is no value on the second floor, and it should be paste file1 file2|awk '{if ($1 == $3 && $2 != $4) print $0}'[/quote]
awk Please tell me
The answer on the third floor is wrong. If the result is
[color=red]00002 31 32
00007 25 28
[/color]
list the $1 that is the same and the $2 that is different.
admirer 2003-9-12 00:45
awk Please advise
This is not a problem that can be solved by simple paste, but a problem connected by keywords!
[code]sort file1 >f1;sort file2 >f2; join -j1 1 f1 f2|awk '$2 != $3'
00002 31 32
00007 25 28[/code]
killua 2003-9-12 03:30
awk Ask for advice
[quote][i]Original post by "yoof"]join -j1 1 f1 f2 Please explain[/quote Posted by:[/i]
With the first one The first field of the file is the index key, connecting the two files f1 and f2
File processing
1. There is a file gz.txt (salary)
4367422926350133100 Zhang San 1250.00
4367422926351220178 Li Si 1300.00
4367422926351220546 Wang Er 0
Su Wubing 1340.00
4367422926351220178 Sun June 1390.00
………
Requirements: Press The account number is 19 digits, the name is 8 digits, and the salary is 8 digits. If the name is less than 8 digits, it should be filled in after, and if the salary is less than 8 digits, it should be filled in before the salary. At the same time, it is required to remove the list with a salary of 0. If there is no account, add 19 spaces in front, and output the total salary for verification. After processing, it should be arranged as follows:
4367422926350133100 Zhang San 1250.00
4367422926351220178 Li Si 1300.00
Su Wubing 1 340.00
4367422926351220178Sun June 1390.00
………
awk program:
#-------------------------------- ------
#shgz1.sh
sblank=" "
awk '$nf!="0"' $1 > tmp.txt #Delete the number of people with a salary of 0
awk '<
if($1!~/[0-9]/)<
printf("%-19.19s%-8.8s%8.2fn","'"$kk"'",$1,$2)> # If there is no account, fill in the spaces
else<
printf("%-19.19s%-8.8s%8.2fn",$1,$2,$3)>
>' tmp.txt > $2
awk '$nf~/[0-9]/<
sum=sum+$nf
>
end<
system("rm tmp.txt")
printf("the sum is%16.2f !n", sum) #Output the total salary
>' $2
When calling system variables in awk, you must use single quotes. If it is double quotes, it means the string
Flag=abcd
awk '{print '$ Flag'}' results in abcd
awk '{print "$Flag"}' results in $Flag
How to remove content between matches but not including matching lines
I have such a file:
Query=4567879
sequence jkaskdjgkjasgasa;jghsafgkas
jfaklslgjdla;;gsdakl;gd
E
PUT-ASD-WEETED-001
PUT-ASD-WEQER5-001789
>PUT-ASD- WEETED-001
SDAGDSDS
>PUT-ASD-WEQER5-001789
DSGTSDTEW
...
...
...
This is it, I want to delete
from score E
To all the lines starting with the first >, but excluding the score E line and the first line starting with >
Use
sed '/score E/,/^>/d' urfile
definitely It doesn't work. Delete the score line E and the first line starting with >?
How to write?
If the file to be processed contains multiple scores, the lines between E and the first one starting with > will be deleted.
awk -v p=1 '/score/{p=0}/>/{p=1}p' urfile
For more awk commands and examples related articles, please follow PHP Chinese website!