i tried the below command: awk '/search-pattern/ {print $1}' How do i write the else part for the above command ?
相关问题
- How to get the return code of a shell script in lu
- Invoking Mirth Connect CLI with Powershell script
- Emacs shell: save commit message
- “command not found” errors in expect script execut
- Python script using subprocess and xclip hangs if
相关文章
- 使用2台跳板机的情况下如何使用scp传文件
- In IntelliJ IDEA, how can I create a key binding t
- shell中反引号 `` 赋值变量问题
- How get the time in milliseconds in FreeBSD?
- What's the difference between grep -r and -R
- Launch interactive SSH bash session from PHP
- Generate disk usage graphs/charts with CLI only to
- How can I create a small IDLE-like Python Shell in
The default action of
awk
is to print a line. You're encouraged to use more idiomatic awkClassic way:
$0
represents the whole input record.Another idiomatic way based on the ternary operator syntax
selector ? if-true-exp : if-false-exp
A straightforward method is,
Here's a simple example,
Equivalent to the above, but without violating the DRY principle:
This is functionally equivalent to
awk '/123/{print "O",$0} !/123/{print "X",$0}' test.txt
Depending what you want to do in the
else
part and other things about your script, choose between these options: