CMD List [11]

Arithmetic Function (awk)

Option or argument

Function

atan2(y,x)

For nawk. Return the arctangent of y/x in radians.

cos(x)

Return the cosine of x

exp(arg)

Return the natural exponent of arg

int(arg)

Return the integer value of arg

log(arg)

Return the natural logarithm of arg

rand()

For nawk. Generate a random number between 0 and 1.

sin(x)

Return the sine of x

sqrt(arg)

Return square root of arg

srand(expr)

For nawk. Use expr to set a new seed for random number generator. Default is time of day.

 

e.g.

awk '{if($3~/48/) print $0}' grade.txt

who | awk '{print $1 " " $NF " is good."}'

 

Calculation & END

ls -l | awk '{ totalsize += $5; print totalsize }'

512

1024

2048

ls -l | awk '{ totalsize += $5; print totalsize }' | tail -1

ls -l | awk '{ totalsize += $5 } END { print totalsize }'

 

Script & Array & Looping – for

awkscript

{

count[length($1)]++

}

END {

for (i=1; i < 9; i++)

print “There are “ count[i] “ accounts with “ i “ letter names.”

}

awk -F: -f awkscript < /etc/passwd

 

Condition – if

awk -F: ‘{ if (length($1) == 1) print $0 }’ < /etc/passwd

ls -l | awk '{if($1=="-rw-r-----") print $9}'

 

1          Error Message

M – message; S – solution.

M: &FILE=/sysp/cdclient/ndm/cfg/cliapi/ndmapi.cfg:&OSERR=13:&OSMSG=Permission denied

S: remove existing log.

 

2          Administration

 

2.1         Get Disk Space

Trimming a Directory - creating new files can make a directory bigger, deleting new files doesn't, it can never get smaller, unless you delete it.

e.g. 1. mv project project.toobig 2. mkdir project 3. mv project.toobig/*.txt project 4. rm -r project.toobig

 

Huge Files Might Not Take a Lot of Disk Space (if a lot of NUL characters in it), ls -ls to find the space allocation.

 

2.2         DOS ftp AIX

ftp <ip>

rename <original name> <new name>

put <local file> <remote file>

asc,pwd,dir,ls,rm,del,bye,Ctrl + C

 

3          Perl

Summary

1) Full name is “Practical Extraction and Report Language”. Slogan “There's More Than One Way To Do It”.

2) Automatically initialize variables and arrays start with a null or 0 value.

3) Like C, PERL statements must end in a semicolon (;).

4) Comments begin with a pound sign (#).

5) First line should mark with #!/usr/local/bin/perl. E.g.

#!/usr/bin/perl -w    # prompt warning

6) list use (), string use ‘’ or “”.

7) compare with Double quotes (“”), Apostrophe (‘’): 1 – can’t replace variable 2 – 反斜线不支持转义字符. 3 – 可以跨多行.

'' – Single Quote / Apostrophe, string no variable replacement

"" - Double quotes, string with variable replacement

`` - Backquote / Backtick, run the command, generate output as input

8) Automatically transform string into numeric. E.g. $result = "12a34" +1; # $result = 13

 

Argument

-e

used to enter one line of program. If -e is given, Perl will not look for a filename in the argument list.

-p

A –p overrides a –n switch. It causes Perl to assume the following loop.

while (<>) {

       ...           # your program goes here

    } continue {

       print or die "-p destination: $!\n";

    }

 

Data Type

Scalars  

纯量, string, number, or a reference. Denoted by $

Arrays of scalars

ordered lists of scalars indexed by number, starting with 0. Denoted by @. Arrays of scalars are faster than associative arrays.

Hashes

known as ‘associative arrays (of scalars)’, unordered collections of scalar indexed by string. Denoted by %

Note: Not divide data type into string, integer and float.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值