sh AWK_NUMBERING_CALCULATIONS

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh AWK_NUMBERING_CALCULATIONS相关的知识,希望对你有一定的参考价值。

awk '{ printf("%5d : %s\n", NR, $0) }'						




# Example:
awk '{ printf("%5d : %s\n", NR, $0) }' FILE_IN > FILE_OT

awk 'NF { $0=++a " :" $0 }; { print }'						


# ex:


awk 'NF { $0=++a " :" $0 }; { print }'	FILE_IN > FILE_OT

awk '{ print NR "\t" $0 }'						

# Example
awk '{ print NR "\t" $0 }'	FILE_IN > FILE_OT
awk '{ total = total + NF }; END { print total+0 }'						






# Ex
awk '{ total = total + NF }; END { print total+0 }' FILE_IN > FILE_OT						
awk 'END { print NR }'						





#Ex:
awk 'END { print NR }' FILE_IN > FILE_OT
1. numbereachline.bash                :   Number lines in each file separately
2. numberallline.bash                 :   Number lines on all files together
3. numberspacecolon.bash              :   Number lines with space and colon
4. numbernonblank.bahs                :   Number non blank lines
5. countlines.bash                    :   Count lines in file (wc -l)
6. sumofallfields.bash                :   Print the sum of all fields in every line
7. sumofallfieldsallines.bash         :   Print the sum of all fields in all lines
8. replaceabs.bash                    :   Replace every field with its abs value
9. countwordstotal.bash               :   Count total number of words per file
awk '{ for (i = 1; i <= NF; i++) s = s+$i }; END { print s+0 }'						



#Ex:
awk '{ for (i = 1; i <= NF; i++) s = s+$i }; END { print s+0 }'	FILE_IN > FILE_OT
awk '{ s = 0; for (i = 1; i <= NF; i++) s = s+$i; print s }'						



# Ex
awk '{ s = 0; for (i = 1; i <= NF; i++) s = s+$i; print s }'	FILE_IN FILE_OT
awk '{ for (i = 1; i <= NF; i++) if ($i < 0) $i = -$i; print }'						





# Ex
awk '{ for (i = 1; i <= NF; i++) if ($i < 0) $i = -$i; print }'	  FILE_IN > FILE_OT					
awk '{ print FNR "\t" $0 }'						


# Example:

awk '{ print FNR "\t" $0 }'	FILE_IN > FILE_OT

以上是关于sh AWK_NUMBERING_CALCULATIONS的主要内容,如果未能解决你的问题,请参考以下文章

sh sh_template.sh

sh sh.sh

Linux下面如何运行 SH文件

配置告警系统主脚本main.sh mon.sh load.sh 502.sh disk.sh

shell 脚本各种执行方式(source ./*.sh, . ./*.sh, ./*.sh)的区别

linux下sh文件的运行