Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1514796
  • 博文数量: 289
  • 博客积分: 11086
  • 博客等级: 上将
  • 技术积分: 3291
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-22 17:06
个人简介

徐小玉的博客。

文章分类

全部博文(289)

文章存档

2023年(6)

2022年(1)

2021年(2)

2020年(9)

2019年(9)

2018年(6)

2017年(10)

2016年(10)

2014年(3)

2013年(4)

2011年(12)

2010年(16)

2009年(14)

2008年(119)

2007年(48)

2006年(20)

我的朋友

分类: Python/Ruby

2016-11-12 09:39:35

2018-01-22

error like the below is shown when using gedit:
(gedit:14333): Gtk-WARNING **: cannot open display: :0.0

It is caused by sudo permission.

run :
xhost +

before sudo to another user, then this will be solved.



2018-0105

du -sh *

2018-0104:

hostname -s:  to get the name of the host only. 

2017-12-25
tar  --exclude: to exclude the folder to be tar..

参数

含义

说明

-z

zip

使用zip进行解压或压缩

-j

bzip2

使用bzip2进行解压或压缩

-c

create

创建一个打包文件

-x

extract

打开一个打包的文件

-v

verbose

显示具体过程

-f

file

指定文件

-C

directory DIR

指定解压的目录

-p

permissions

保持文件的所有属性

-P

absolute-names

保持绝对路径开头的"/"

-X

--exclude

排除不处理的文件


/bin/tar -jcf   a.tar.bz2 a.git --exclude=a.git/.git



============
awk  使用参数的方法:

mc_month=`date|awk '{print $2}'`
mc_day=`date|awk '{print $3}'`

#ls -ltr |awk '{ if ( $6=="Aug" && $7=="18" ) print $9}'

ls -ltr |awk '{ if ( $6=="'$mc_month'" && $7=="'$mc_day'") print $9}'


-------------------------------
ftp如何不要提示用mget自动连续get多个文件?
#bin
#prompt
#mget XXXXXXXX

-------------------------------
 zip -q -r test3 ttt ( zip  [参数] 目标名,压缩的目录路径)
unzip -v  只看,不解压。
====================
for i in $(ls *.pl) ;do echo "Curent is $i" ;done 
=======================================
ls -F
-F 选项会在显示目录条目时,在目录后加一个/
ls -F |grep "/$"  显示路径
ls -l |grep "^d"|awk '{print $9}' 显示路径

ls -l |grep "^[^t] " 去掉显示total 36
===========================
#!/usr/bin/ksh
#数字段形式
for i in {1..10}
do
   echo $i
done
#详细列出(字符且项数不多)
for File in 1 2 3 4 5
do
    echo $File
done
#对存在的文件进行循环
for shname in `ls *.sh`
do
          name=`echo "$shname" | awk -F. '{print $1}'`         
          echo $name
done
#查找循环(ls数据量太大的时候也可以用这种方法)
for shname in `find . -type f -name "*.sh"`
do
          name=`echo "$shname" | awk -F/ '{print $2}'`        
          echo $name
done
#((语法循环--有点像C语法,但记得双括号
for((i=1;i<100;i++))
do
    if((i%3==0))
    then
        echo $i
        continue
    fi
done
#seq形式 起始从1开始
for i in `seq 100`
do
    if((i%3==0))
    then
        echo $i
        continue
    fi
done
#while循环注意为方括号[],且注意空格
min=1
max=100
while [ $min -le $max ]
do
    echo $min
    min=`expr $min + 1`
done 
#双括号形式,内部结构有点像C的语法,注意赋值:i=$(($i+1))
i=1
while(($i<100))
do
    if(($i%4==0))
    then
        echo $i
    fi
    i=$(($i+1))
done
#从配置文件读取,并可以控制进程数量
MAX_RUN_NUM=8
cat cfg/res_card_partition.cfg |grep -v '^$'|grep -v "#" | grep -v grep |while read partition
do      
                nohup sh inv_res_card_process.sh $partition >log/resCard$partition.log 2>&1 &             
                while [ 1 -eq 1 ]
                do
                                psNum=`ps -ef | grep "inv_res_card_process" | grep -v "grep" | wc -l`
                                if [ $psNum -ge $MAX_RUN_NUM ]
                                then
                                              sleep 5
                                else
                                              break
                                 fi                                      
                done              
done

# 三.循环控制语句
# break 命令不执行当前循环体内break下面的语句从当前循环退出.
# continue 命令是程序在本循体内忽略下面的语句,从循环头开始执行
===============================
set -A  hi `ls -F|grep "/$"| awk "/^[a-z][a-z]\//"|cut -c1-2`
num=${#hi[*]}
echo " Number of the array is: $num"
id=0
while [ $id -lt $num ]
do
 echo "Number $id: ${hi[$id]}"
cd /sas/dev/mva-v940m2/LOG/WX6NO/${hi[$id]}
  pwd
#bldstat -w -e * |grep '[0-9]\{6\}' |awk '{print $9}'
bldstat -w - * |grep '[0-9]\{6\}'
   let "id=id+1"
done

======================
# 判断变量是否为空
if [ -z ${A} ]; then
...
fi
# 得到字符串的长度
str="hello"
echo ${str} | wc -L


========================
由于ls没有提供只显示目录的命令,所以我们只要搭配grep命令来显示目录
1、ls -F |grep "/$"
显示目录(不包含.及..),当然也可以包含,使用命令:ls -Fa |grep "/$"
2、ls -la |grep "^d"
显示当前目录的所有目录
========================
ps -o pid,ppid,tty,state,args,wchan
ps -lA|grep 84187
ps aux |grep 84187
==================================

得到目录:
ls -ltr | grep '^d' |awk '{if ($9 ~ /^[a-z][a-z]$/) {print $9}}'   (只显示俩字符的)
ls -ltr | grep '^d' |awk '{print $9}'

======================
ps -aux |grep buildsrc
pstree -pa 58921
ps -ww 79471
==================================

#metabuild unx -b d4deploy02 --checkonly --notrackdep -l dev -g | grep -E -A6 "failed "  |awk '{ if(NR%6==0) {print $4}}'
显示后6行, 第六行就打印出第4个。
grep显示前后几行

==================================================
find 命令排除某个目录不搜:
find .  -path "./LOG" -prune -o -mtime -2 |xargs grep "tkqc" 
find .  -path "./LOG" -prune -o -mtime -2 -name "*.m" |xargs grep  "NPREG"  :定义在npreg.m  所以搜索包含NPREG的.m文件
find .  -path "./LOG" -prune -o  -name "*.h" |xargs grep "CRFNOVARS" 

find . -path "./LOG" -prune -o -mtime -4 |xargs grep "TK_BUGDCLINIT"
-mtime 按文件更改时间查找
 -atime  按文件访问时间查找
 -ctime  按文件创建时间查找
对多个文件夹排除:
find /usr/sam /( -path /usr/sam/dir1 -o -path /usr/sam/file1 /) -prune -o -print
圆括号表示表达式的结合。 / 表示引用,即指示 shell 不对后面的字符作特殊解释,而留给 find 命令去解释其意义。
 查找某一确定文件,-name等选项加在-o 之后
 
#find /usr/sam /(-path /usr/sam/dir1 -o -path /usr/sam/file1 /) -prune -o -name "temp" -print
================

my_date=`date +%Y%m%d`         20120926
==========================
 
 合并行。 把一个文件的一列列合并成一行。
 awk '{printf"%s ", $0}'
=============
 
ftp:
root@BZXXDBS02 ~]# service vsftpd start
vsftpd: unrecognized service

/etc/xinetd.d/gssftp
vi   /etc/xinetd.d/gssftp  把disable=yes改成no,然后打开ftp服务
把server_args     = -l -a  改成  server_args     = -l  把 -a 去掉,这样系统的用户才有权限用ftp登陆
[root@BRDVM0289 /]# service xinetd restart
Stopping xinetd: [  OK  ]
Starting xinetd: [  OK  ]
查看21端口:
[root@BRDVM0289 /]# netstat -tnl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State     
tcp        0      0 127.0.0.1:2208              0.0.0.0:*                   LISTEN     
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN     
tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN     
tcp        0      0 0.0.0.0:918                 0.0.0.0:*                   LISTEN     
tcp        0      0 0.0.0.0:23                  0.0.0.0:*                   LISTEN     
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN     
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN     
tcp        0      0 127.0.0.1:2207              0.0.0.0:*                   LISTEN     
tcp        0      0 :::22                       :::*                        LISTEN


=====================================================
unset:
unset names   把names 中列出的变量或函数的定义删除。
==================================================
sed 变量:
sed -n "2,$times_end"p

取得前一天的时间:
date +%Y%m%d -d'-11 day'  但是很多系统下不行。

date +%Y%m%d
20110921
date +%p
AM

Sep 02, 2011
 显示目录:
 
呵呵,网上这样说,ls -F | grep "/$"
ll | grep "^d"

===============================================
按第6个字段(日期)排序,然后选出是9月的:
sort +5 hotfix.B25155.2>hotfix.B25155.fini
nawk '{ if ( $6 == "Sep" ) print $9}' hotfix.B25155.fini
ls -ltr /sasgen/dev/mva-v930f/stat/*/*/* | nawk '{ if ( $6 == "Sep" && $7 == "15" ) print $0 }' |grep mvsnd



===========================================
如何去掉行末的^M:

如果就一个文件是这样,可以在vi打开该文件后,输入
:%s/^M//g
我测试过,可以的
我测试过,为何不可以?[/quote]
^M是先按ctrl+v再按ctrl+m出来的
======================
while read line
do
  your command...
done < tmp
=========================================================
Augest 19
1: whence [ command ]
 Prints information about the command
 > whence ls
/bin/ls
 > whence -v ls
ls is a tracked alias for /bin/ls
2:
 

=========================================================

Augest 17
注释掉一段代码
:< ...
segment
...
BLOCK

==================================================================================================================
==================================================================================================================
==================================================================================================================
==================================================================================================================
==================================================================================================================
==================================================================================================================
==================================================================================================================
==================================================================================================================

Augest 3

----------------------------------------------------
1: set -x
  在每个简单命令被扩展之后,显示PS4扩展值,之后是要执行的命令
 
   set -  ??????
2:grep -c
   The –c option causes grep to print the number of lines where the pattern was found

=========================================================

Augest 17
----------------------------------------------------
cmp命令的使用:
/usr/bin/cmp
比较两个文件。
cmp dest src 
如果不同,显示一个不同的位置: dest sirc: char4,line 1.
 如果显示cmp:EOF on dest,则 src的第一部分与dest  相同,但dest还有其他数据。
 
cmp -s dest src   :不给出任何信息,如果相同,给出值0,不同,1。 错误,2。
if cmp -s dest src
then
echo no change
fi
--------------------------------------------

Mar 27
 $? 对测试结果特别有用
-----------------------------------------
Mar 26
1: 删除大量文件的方法:
   find . -type f |xargs rm
------------------------------------------
Mar 18
echo $(ls -l) :  显示结果不带换行。
echo "$(ls 0l)" 显示结果带换行。
3: “” 可以阻止对字符的分割,只要用双引号括起来,就是一个变量。
4:

---------------------------------
Jan 12
 1:xargs的使用
Xargs把一条命令在标准输出上的输出结果,转换为另一个程序或者另一个命令的参数。、
它与普通管道的区别在于下面的一个例子:
(1)$find . -name "install.log" -print | cat
./install.log   #显示从管道传来的内容,仅仅作为字符串来处理
(2)$find . -name "install.log" -print | xargs cat
aaaaaa        #将管道传来的内容作为文件,交给cat执行。也就是说,该命令执行的是如果存在install.log,那么就打印出这个文件的内容。
2008
Nov 28
1:  vim中如果不想显示行号:
    :se nonu
2:ftp 如果要用-u参数,在crontab里工作的话,要加绝对路径
3:awk 'BEGIN {FS=OFS="|"} {{if ($1 == "178") $2="program2"} print}' ufile
4:sed '/^178/s/program/program12/' ufile
   awk -F\| -v OFS=\| '/^178/{$2="program12"}1'

-----------------------------------
Nov 27
1: 常用文件重定向命令
command > filename 把把标准输出重定向到一个新文件中
command >> filename 把把标准输出重定向到一个文件中(追加)
command 1 > fielname 把把标准输出重定向到一个文件中
command > filename 2>&1 把把标准输出和标准错误一起重定向到一个文件中
command 2 > filename 把把标准错误重定向到一个文件中
command 2 >> filename 把把标准输出重定向到一个文件中(追加)
command >> filename 2>&1 把把标准输出和标准错误一起重定向到一个文件中(追加)
command < filename >filename2 把command命令以filename文件作为标准输入,以filename2文件作为标准输出
command < filename 把command命令以filename文件作为标准输入
command << delimiter 把从标准输入中读入,直至遇到delimiter分界符
command <&m 把把文件描述符m作为标准输入
command >&m 把把标准输出重定向到文件描述符m中
command <&- 把关闭标准输入
--------------------------------------
Nov 14
1: date  的用法:
 date +%0H:%0M
03:53
 date +%0w
5
 date +%d
14
 date +%m
11
 date +%y
08
----------------------------------
Nov 06
1: 获得变量长度的方法:(据说是ksh)
  #echo $PWD
     /r/sanyo.unx.sas.com/vol/vol5/u51/scnyam/meiplaypen/mei_shell
     # echo ${#PWD}
     61
2: typeset的-R 选项:-R4 把变量变成一个又对齐的4个字符串 (左对齐的用L)
  >typeset -R4 var=adcdefg
  >echo $var
     defg
3: typeset 取得左侧俩字符,转化成大写:
    typeset -uL2
 
4: 关于if 的两个参数-r , -s
    -r:
   return a True exit value is the specified Filename exists and is readable by the current process.
     -s
    return a True exit value is the specified Filename exists and has a size greater than  0.
   
Oct 06
typeset -u可以把小写转换成大写。
2:  ME=${0##*/} 显示程序名
     与$0的区别是:
     ME=${0##*/}  echo $ME   : TEST.sh
  name=$0 echo $name      :./TEST.sh
  
May 30
1:
   echo $SHELL           查看当前用户默认的SHELL
   echo  $0                     查看用户当前的SHELL
May 29
   1:  a 目录下有如下文件:
   ubantu_123.txt   linux.32a.txt    debian-fke.dle.txt 等等前缀相同的N多文件。。。。
   要求将不同前缀的分类移动到,以该前缀命名的目录下(这些目录要在脚本中自动建立!)!!!!
    如:ubantu_123.txt  在./ubantu/ubantu_123.txt         linux.32a.txt     ./linux/linux.32a.txt
   实现:
   代码:for i in `ls *.txt`;do dir=`echo $i|awk -F'[_\.]' '{print $1}'`;mkdir $dir;cp $i ./$dir; done
   2:
    whoami  ==> 显示当前有效用户
who am i ==> 显示login id
#!/bin/sh
#hell2.sh -- 用来向用户问好。
if [ $# -ne 1 ] ;
then
echo "Usage: $0 username";
exit 1;
else
echo "Hello World, Hello $1 !";
fi
这把看懂了么?有点意思吧?下面给你解释一下:
1. [...] 是用来测试。
2. -ne 表示不等于
3. if 用于判断,和then else 联合使用,以 fi 结束
4. $# 表示参数个数
5. $0 表示脚本名称
6. $1 表示第一个参数。

Unix shell by example
Chapter 8
Table 8.3. Bourne Shell Positional Parameters
Positional Parameter What It References
$0 References the name of the script
$# Holds the value of the number of positional parameters
$* Lists all of the positional parameters
$@ Means the same as $*, except when enclosed in double quotes
"$*" Expands to a single argument (e.g., "$1 $2 $3")
"$@" Expands to separate arguments (e.g., "$1" "$2" "$3")
$1 .. $9 References up to nine positional parameters
例子:#!/usr/bin/sh
echo " this script is called $0"
echo " $0  and $1 $2 $3  $4"
echo " the \$*  is  $*"
echo " the number of positional parameters is $#"
结果:
$ greetings.sh tom Mei Yan  lIng
 this script is called greetings.sh
 greetings.sh  and tom Mei Yan  lIng
 the $*  is  tom Mei Yan lIng
 the number of positional parameters is 4

name=${1:?"requires an argument" }   #  需要参数,如果$1存在,,那么就正常执行,否则,提示这样的信息。
   echo Hello $name
String, Integer, and File Testing
Table 8.4. String, Integer, and File Testing
Test Operator Test For
String Test
string1 = string2 String1 is equal to String2 (space surrounding = required)
string1 != string2 String1 is not equal to String2 (space surrounding != required)
string String is not null
–z string Length of string is zero
–n string Length of string is nonzero
  EXAMPLE
test -n $word      or      [ -n $word ]
test tom = sue      or      [ tom = sue ]

Integer Test
int1 –eq int2 Int1 is equal to int2
int1 –ne int2 Int1 is not equal to int2
int1 –gt int2 Int1 is greater than int2
int1 –ge int2 Int1 is greater than or equal to int2
int1 –lt int2 Int1 is less than int2
int1 –le int2 Int1 is less than or equal to int2
Logical Test
expr1 -a expr2 Logical AND
expr1 -o expr2 Logical OR
! expr Logical NOT
File Test
–b filename Block special file
–c filename Character special file
–d filename Directory existence
–f filename Regular file existence and not a directory
–g filename Set-group-ID is set
–k filename Sticky bit is set
–p filename File is a named pipe
–r filename File is readable
–s filename File is nonzero size
–u filename Set-user-ID bit is set
–w filename File is writable
–x filename File is executable
Case语句
case variable in
value1)
    command(s)
    ;;
value2)
    command(s)
    ;;
*)
command(s)
    ;;
Esac
制造菜单
cat << ENDIT
        1) vt 120
        2) wyse50
        3) sun
2 ENDIT
read choice
case "$choice" in
   …
Exec命令
Shift
#!/bin/sh
1    set joe mary tom sam
2    shift
3    echo $*
4    set `date`
5    echo  $*
6    shift 5
7    echo  $*
8    shift 2

(The Output)
3    mary tom sam
5    Fri Sep 9 10:00:12 PDT 2004
7    2004
8 cannot shift
在一个程序里调用另一个程序里的函数的方法。(不对)
Function.sh:
#!/usr/bin/sh
increment()
{
  sum=`expr $1 + $2`;
  return $sum;
}
Func_father.sh
#!/usr/bin/sh
. function.sh
increment 4 5
(output)
Chapter 7
?  uname –n
  显示机器名。
   uname –a 
AIX ODP590-1 3 5 00CD7B9F4C00
Chapter 6
? % awk '/Tom/,/Suzanne/' filename
查找文件中 tom 与suzanne中的内容,显示出来。
如果一直没出现sunzanne ,则,一直显示到结尾。
如果在出现了一对后,又出现一个tom ,则显示到另一个suzanne为止。
? awk '$2 == "NW" || $1 ~ /south/ {print $1,$2}' datafile
记住,等于一个具体的串要加””
? awk '!($8==13) ' datafile
? awk '/southern/{print $8 - 10}' datafile
? awk ' $3 ~/Susan/ {printf "the percent is :" $6+ .2  "volume:" $8}' datafile   变成两位小数点。
? awk ' {print ($7 >4 )? "high" $7: "low " $7 }'  datafile
? awk '$3=="Chris"{$3 = "Christian";print }' datafile
如果第三个字段等于chris ,就把第三个字段赋植为”Christian “
? awk '/Derek/{$8 +=12;print }' datafile
把Derek所在的行的第8个字段加12
? awk '{$7 %= 3; print $7}' datafile
For each record, the seventh field ($7) is divided by 3, and the remainder of that division (modulus) is assigned to the seventh field and printed.
?   Awk中使用的内置变量
  
Variable Name Contents
ARGC Number of command-line argument
ARGIND Index in ARGV of the current file being processed from the command line (gawk only)
ARGV Array of command-line arguments
CONVFMT Conversion format for numbers, %.6g, by default (gawk only)
ENVIRON An array containing the values of the current environment variables passed in from the shell
ERRNO Contains a string describing a system error occurring from redirection when reading from the getline function or when using the close function (gawk only)
FIELDWIDTHS A whitespace-separated list of fieldwidths used instead of FS when splitting records of fixed fieldwidth (gawk only)
FILENAME Name of current input file
FNR Record number in current file
FS The input field separator, by default a space
IGNORECASE Turns off case sensitivity in regular expressions and string operations (gawk only)
NF Number of fields in current record
NR Number of records so far
OFMT Output format for numbers
OFS Output field separator
ORS Output record separator
RLENGTH Length of string matched by match function
RS Input record separator
RSTART Offset of string matched by match function
RT The record terminator; gawk sets it to the input text that matched the character or regex specified by RS
SUBSEP Subscript separator
? gawk  –F:  '{IGNORECASE=1};   $1 == "mary adams"{print NR, $1, $2,$NF}' employees2
? nawk 'BEGIN{FS=":"; OFS="\t"; ORS="\n\n"}{print $1,$2,$3}' file
   nawk 'BEGIN{print "MAKE YEAR"}'
awk 会在begin 完全结束后才开始读行,所以begin模块基本上都是处理些指定内置变量了,给变量赋值了,输出些提示信息了,等等的操作。  并且它都是用{}与实际读行分隔的。
? END模块
$ nawk 'END{print "The number of records is " NR }' lab4
The number of records is 12
$ nawk '/Mary/{count++}END{print "Mary was found " count " times."}' employees
Mary was found 1 times.
     $ nawk 'END{print "HEllo World!"}' lab4
END模块在所所数据行处理完之后执行,所以,它必须有处理文件,这与bgein不同。
? 重定向
输出重定向:
awk 'BEGIN{FS=":";OFS=":"} {print $1,$2>"filename"}' lab4
   重定向的文件名必须家双引号。
输入重定:
    getline 函数
nawk 'BEGIN{ "date" | getline d; print d}'
nawk '{print $1, $2 | "sort –r +1 –2 +0 –1 "}' names
:   用第二个字段做主键,第一个字段做二键,反向排序
   注意,要用双引号。
? System 函数作用
awk 'BEGIN{FS=":";OFS=":";system("ls")} {print $1,$2}' lab4
system(“ls”)
  系统命令要放在””里。
? Awk:
   Awk.sc: 
BEGIN{ FS=":"; print "\t ***CAMPAIGN 1998 CONTRIBUTIONS*** \n --------------------------------- \n name \t\t\t phone \t\t\t  jan| feb| mar| Total \n --------\n"} \
  {count1=$3+$4+$5;  bigger=($3>$4)?$3:$4;biggest=(bigger>$5)?bigger:$5;   print $1 ,"\t\t\t",$2 ,"\t\t\t",$3,$4,$5,count1} \
  {count=count+count1}\
  {ave=count/12} 
  END{print " --------------------------------------------------------------- \n \t\t\t SUMMARY  \n -------------------------------------------------------------\n "\
 " the total contrbution is : " count  "\n the average of the 12 month is : "ave   \
 " the biggest is : " biggest}
  Awk –f awk.sc lab5 
  这是lab5的答案。

? nawk '{count[$2]++}END{for(name in count)print name,count[name] }' employees
nawk '/^Tom/{name[NR]=$1};END{for( i = 1; i <= NR; i++ )print name[i]}' db

nawk  '{dup[$2]++; if (dup[$2] > 1){name[$2]++ }}  END{print "The duplicates were"  for (i in name){print i, name[i]}}' datafile4
nawk BEGIN{ split( "3/15/2004", date, "/"); print "The month is " date[1] "and the year is "date[3]"} filename
(The Output)
The month is 3 and the year is 2004.  把串3/15/2004存到date里,分隔符为/

BEGIN{for ( i=0; i < ARGC; i++ ){  printf("argv[%d] is %s\n", i, ARGV[i])} printf("The number of arguments, ARGC=%d\n", ARGC)}
Argc: 参数个数。
Argv : 参数数组。
? #  match 函数。
$ awk 'END{start=match("Good ole USA",/[A-S]+$/);print start,RSTART,RLENGTH}' employees
11 11 2
#  match 函数。
$ awk 'BEGIN{line="HEllo Santa Claus USA"} END{match(line,/[A-Z]+$/);print substr(line,RSTART,RLENGTH)}' employees
USA



 

nawk 'NR==2,NR==5  {print NR,$0}' datafile :  2-5行的数据输出
nawk 'BEGIN{OFMT="%.2f";print 1.2456789}'        1.25
$ awk 'BEGIN{print "\t\tWeocome to here "}{Count++}END{print Count}' datafile                 Weocome to here
9
 
 

Apr 26
2: 怎样返回grep的值到一个变量中。
   #/bin/bash
grep "abc" filename
reval=$?
echo "grep return value: $value"
exit 0
1
请问各位ld,用sed不用"-e"选项能否实现一次删除多个不连续的行?
比喻文件a的内容为 (cat -n a)
1 this is 1 line,
2 this is 2 line,
3 this is 3 line,
4 this is 4 line,
5 this is 5 line,
6 this is 6 line,
7 this is 7 line,
8 this is 8 line.
现在要删除第1行,第3行至第5行,第7行,即只剩下2,6,8行。
请问如何实现,感谢之至!!!
:em02:  :em02:
sed '1d;3,5d;7d' a
2:
  Awk中使用变量的办法:
   phonenumber=`sed -n 1p phone.txt`      # 得到每一个手机号码
   echo phonenumber:$phonenumber
 
    awk  '/'$phonenumber'/{print NR, $0  }' CMODSI_20070403050655_768.dat
11月8日
计算文件行数:
提取最后一行行号??直接当变量用??
wc -l file
tail -n 1 file
awk 'END{ print FILENAME ": " NR ":", $0}' file
输出重定向到一个文本文件里??
cmd >> file.log
老实说看不懂你要问什么.....
********************8
find . -type f -exec wc -l {} \;
find . -type f -exec
 {} \; | awk '{t+=$1} END {print  t}'

cat youfile|sed -e 's^,//g' |awk 'BEGIN{i=0};{i+=$1};END{print i}'
12月13日
一、 用户登陆进入系统后的系统环境变量:
$HOME 使用者自己的目录
$PATH 执行命令时所搜寻的目录
$TZ 时区
$MAILCHECK 每隔多少秒检查是否有新的信件
$PS1 在命令列时的提示号
$PS2 当命令尚未打完时,Shell 要求再输入时的提示号
$MANPATH man 指令的搜寻路径
六、测试字符串
字符串1 = 字符串2 当两个字串相等时为真
字符串1 != 字符串2 当两个字串不等时为真
-n 字符串      当字符串的长度大于0时为真
-z 字符串      当字符串的长度为0时为真
字符串       当串字符串为非空时为真
七、测试两个整数关系
数字1 -eq 数字2     两数相等为真
数字1 -ne 数字2     两数不等为真
数字1 -gt 数字2     数字1大于数字2为真
数字1 -ge 数字2     数字1大于等于数字2为真
数字1 -lt 数字2     数字1小于数字2为真
数字1 -le 数字2     数字1小于等于数字2为真
八、逻辑测试
-a         与
-o        或
!        非
1月4日
1. xargs:
    A filter for feeding arguments to a command, and also a tool for assembling the commands themselves. It breaks a data stream into small enough chunks for filters and commands to process. Consider it as a powerful replacement for backquotes. In situations where command substitution fails with a too many arguments error, substituting xargs often works. [1] Normally, xargs reads from stdin or from a pipe, but it can also be given the output of a file.
2. date的妙用
  
   Date +%j  获得从这年的开始,到目前 第多少天
   Date +%s  从1970-1-1  到现在多少天。  这个在生成临时文件是十分有用。:
        prefix=temp
          suffix=$(date +%s)  # The "+%s" option to 'date' is GNU-specific.
          filename=$prefix.$suffix
           echo $filename
           #  It's great for creating "unique" temp filenames, even better than using $$.
The -u option gives the UTC (Universal Coordinated Time).
      //格林尼制标准时间不是GMT吗?
3. zdump
Time zone dump: echoes the time in a specified time zone.
4. Cal :打出个小日历。
5. uniq
This filter removes duplicate lines from a sorted file. It is often seen in a pipe coupled with sort.
   1 cat list-1 list-2 list-3 | sort | uniq > final.list
The useful -c option prefixes each line of the input file with its number of occurrences
1月10日
1. Fold and fmt
都是把数据按照指定的宽度分割。
Fold –s –w inputfile   :按照宽度W把输入数据切割,S选项保证不会把同一个单词切割开(也就是用空格区分单词。)
Fmt –w inputfile   作用和Fold –s –w inputfile基本相同,但也有细微差别
Fold –s –w inputfile 当宽度小于两个单词而大于一个单词的时候,会将第二个单词割断。 而Fmt –w inputfile不会。
1月12日
1. 在查看文件是否存在的时候特别有用的3个命令
Which
Whereis
whatis
后面直接加命令就可以
Which  awk
2. Vdir
功能与ls –l功能相同
3. Locate slocate
Locate 文件名   获得文件的位置,带绝对路径。
1月18日
1 Tr
字符串过滤转换的命令
Either tr "A-Z" "*"
-c  替换命令
bash$ echo "acfdeb123" | tr -c b-d +
      +c+d+b++++
2 Seq(jot)
These utilities emit a sequence of integers, with a user-selected increment
Seq按照用户指定的增量,生成一串整数,默认状态是增量为1
bash$ seq 5
 1
       2
 3
 4
 5
 
        bash$ seq -s : 5
       1:2:3:4:5
  在FOR循环里,很有用处。
 1) for a in `seq 80`   (for a in 1  2 3   ….80)
2) COUNT=80
 for a in `seq $COUNT`  # or   for a in $( seq $COUNT )
 3)  BEGIN=75
     END=80  
    for a in `seq $BEGIN $END`  (for a in 75 76 77 78 79 80)
4) BEGIN=45
  INTERVAL=5
   END=60  
   for a in `seq $BEGIN $INTERVAL $END`(for in 45 50 55 60 )
Mar 07
1 :
 there is a file named diff :
      It have some lines like such :
kxjp.com.               3600    IN      NS      park27.secureserver.net.
kxjp.com.               3600    IN      NS      park28.secureserver.net.
zyzygs.com.             172800  IN      NS      ns1.dns-diy.com.
zyzygs.com.             172800  IN      NS      ns2.dns-diy.com.
 it is ,there are some same lines , now ,I  hope to   evey lines are unique.. ,in other words ,I hope remove the same lines .
  I  can realize it by he way:
awk '!aa[$1]++'  diff
 
OR:
sort -k 1,1 –u  diff
 
2    
there are two files  :
a: 123
b:456
now ,I hope to reunion a new file :  123456
the  error method : cat a b
                 123
                  456
Now ,the true way:
     cat a b|awk 'BEGIN{RS="AAA"}{gsub(/\n/,"",$0);print}'
OR
sed "s/.*/&$(/odfs01/odtemp3/1boss3ftp/RATEDEDR/MZ_DZK_200711_"$date".dat VARCHAR
zcat是处理压缩文件的cat命令
zgrep是处理压缩文件的grep命令
NOV 1 
ps -T 0
ps -T 1
 查出子孙进程
 
Sep 10  关于压缩。
 压缩:
tar
解包: tar xvf FileName.tar
打包:tar cvf FileName.tar DirName
(注:tar是打包,不是压缩!)
---------------------------------------------
.gz
解压1:gunzip FileName.gz
解压2:gzip -d FileName.gz
压缩:gzip FileName
.tar.gz
解压:tar zxvf FileName.tar.gz
压缩:tar zcvf FileName.tar.gz DirName.bz2
解压1:bzip2 -d FileName.bz2
解压2:bunzip2 FileName.bz2
压缩: bzip2 -z FileName
.tar.bz2
解压:tar jxvf FileName.tar.bz2
压缩:tar jcvf FileName.tar.bz2 DirName
---------------------------------------------
.bz
解压1:bzip2 -d FileName.bz
解压2:bunzip2 FileName.bz
压缩:未知
.tar.bz
解压:tar jxvf FileName.tar.bz
压缩:未知
---------------------------------------------
.Z
解压:uncompress FileName.Z
压缩:compress FileName
.tar.Z
解压:tar Zxvf FileName.tar.Z
压缩:tar Zcvf FileName.tar.Z DirName
---------------------------------------------
.tgz
解压:tar zxvf FileName.tgz
压缩:未知
.tar.tgz
解压:tar zxvf FileName.tar.tgz
压缩:tar zcvf FileName.tar.tgz FileName
---------------------------------------------
.zip
解压:unzip FileName.zip
压缩:zip FileName.zip DirName
---------------------------------------------
.rar
解压:rar e FileName.rar
压缩:rar a FileName.rar

rar请到: 下载!
解压后请将rar_static拷贝到/usr/bin目录(其他由$PATH环境变量指定的目录也可以):
[root@www2 tmp]# cp rar_static /usr/bin/rar
---------------------------------------------
.lha
解压:lha -e FileName.lha
压缩:lha -a FileName.lha FileName
lha请到:下载!
>解压后请将lha拷贝到/usr/bin目录(其他由$PATH环境变量指定的目录也可以):
[root@www2 tmp]# cp lha /usr/bin/
---------------------------------------------
.rpm
解包:rpm2cpio FileName.rpm | cpio -div
---------------------------------------------
.tar .tgz .tar.gz .tar.Z .tar.bz .tar.bz2 .zip .cpio .rpm .deb .slp .arj .rar .ace .lha .lzh
.lzx .lzs .arc .sda .sfx .lnx .zoo .cab .kar .cpt .pit .sit .sea
解压:sEx x FileName.*
压缩:sEx a FileName.* FileName
sEx只是调用相关程序,本身并无压缩、解压功能,请注意!
sEx请到: 下载!
解压后请将sEx拷贝到/usr/bin目录(其他由$PATH环境变量指定的目录也可以):
[root@www2 tmp]# cp sEx /usr/bin/
Shell命令
Cut
     -c   指定cut哪几个字符。
      -f  指定得到哪几列, -d指定分割符。 
       Cut –f 1,7  -d -    将得到用-分割的第一和第7列
Cut –f 1-7  -d -    将得到用-分割的第一到第7列
Date
  
date +%Y%m%d  :   
    结果 :20071115
date –u             公元2007年11月14日  星期三  02时27分11秒
 
 
Id
Id
uid=205(ondemand) gid=205(ondemand) groups=1(staff)     分别是用户名(id),主组(id),附加组(id)
wholenum.sh (注意什么都不做的时候的if语句模块的使用)
# Name:wholenum
    # Purpose:The expr command tests that the user enters an integer
    echo "Enter a number."
    read number
   if expr "$number" + 0 > /dev/null 2>&1
    then
       :          #  写个冒号就可以了。
    else
       echo "You did not enter an integer value." 1782
        exit 1
    fi
: $? 退出状态。
$ echo  $?
    1               Failure
Ls –d 
只显示目录,不显示文件
 

shell环境变量

如果你希望把你定义的变量让其他所有的shell程序都能使用,也就是定义新的环境变量。你只要使用export关键词就可以了
export MY_NAME=Winter
export PATH=/home/winter/bin:$PATH
上面的程序中,第一行输出MY_NAME变量,第二行是在环境变量PATH中增加一个路径/home/winter/bin 。


 
 

阅读(2188) | 评论(0) | 转发(0) |
0

上一篇:oracle 记录。

下一篇:oracle union

给主人留下些什么吧!~~