📌  相关文章
📜  bash 打印以字符串开头的字段 - Shell-Bash 代码示例

📅  最后修改于: 2022-03-11 14:51:15.310000             🧑  作者: Mango

代码示例1
# Basic syntax:
awk '{ for(i=1; i<=NF; i++) { if($i ~ /^string/) { print $i }}}' your_file
# Where:
#    - for(i=1; i<=NF; i++) - this loops through the fields in each row of
#        your_file, starting at field 1 and ending at the number of fields
#        NF in the current row. Without using a custom delimiter, awk
#        treats spaces, tabs, and new lines as delimiters.
#    - if($i ~ /^string/) - this checks if $i (the current field) begins
#        with "string". The tilde character (~) is shorthand for "check 
#        the operands on either side to see if they match". /^string/ is
#        a regex expression where ^ indicates the beginning of the text.
#        If the if statement is true, the action (print $i) is performed.