- 论坛徽章:
- 0
|
1.awk -F 指定FS(字段分隔符),后接一个正则表达式。
第一个相当于FS的默认值,包括一个或多个空白字符(空格与制表字符)的情况,并会忽略掉行的开头和结尾的空白。
第二个是指字段分隔符正好匹配一个空格。
第三个是指字段分隔符匹配一个或多个空白字符,不会忽略行的开头和结尾的空白。
--------------------------------------------------------------------------------
2.区别:
sed -n '/foo1/,/foo2/p' 寻找foo2要从foo1所在的那行记录之后的记录开始(),不包括foo1所在的行记录
awk '/foo1/,/foo2/' 寻找foo2从foo1所在的那行记录开始,包括foo1所在的行记录
例如:
foo1 hello foo2
hello
foo2
sed -n '/foo1/,/foo2/p'会输出:
foo1 hello foo2
hello
foo2
而awk '/foo1/,/foo2/'仅会输出:
foo1 hello foo2
--------------------------------------------------------------------------------
3.
s="{1,2,3,4,5,a,b,c}";eval "echo $s$s$s$s$s$s$s$s"|tr ' ' '\n'|egrep -v '(\w).*\1'
想法很简单,但效率很低
--------------------------------------------------------------------------------
4.
echo 'aaabcccaaabbbccc'>tmp1.file;sed 's/&\n/g' tmp1.file>tmp2.file;awk '!found[$0]++' tmp2.file>tmp1.file;tr -d
'\n'<tmp1.file;rm -f tmp1.file tmp2.file
其实还是用管道.
--------------------------------------------------------------------------------
5.
因为$(...)命令替换把结尾的换行符(tailing newline)去掉了,而\必须后跟换行符才被解释为续行符。
6.
---------------------------------------------------------------------------------
系统默认的IFS为<space>,<tab>,<newline>。对于不加双引号的$(<urlfile)的情况,urlfile文件的内容被IFS分隔为四个字段,继而
成为echo的四个参数,所以结果就是那样了。
--------------------------------------------------------------------------------
7.
a在c之前的:
cat test|tr '\n' '#'|sed 's/^[^a]*//'|sed 's/[^c]*$s/^#//'|tr '#' '\n'
c在a之前的情况,将上式中的a和c互换一下就行了。
#是一个中介字符,要求在所有输入行中不存在。
--------------------------------------------------------------------------------
8.
seq 8|awk '{print $0,$0+1,$0+2;}'|sed 's/10//'
-------------------------------------------------------------------------------
9. 生成密码用到了mkpasswd,可以安装expect来获得这个命令
#!/bin/bash
#The file client.list contains the 1000 client ip address
#The file success contains the client for which the oracle password was updated successfully.
#The file failure.list contains the client for which there exited something wrong when updating password.
SUCCESS=0
for client in $(cat client.list)
do
password=$(mkpasswd)
result=$(echo $password|ssh $client passwd --stdin oracle)
if [ "$?" -eq $SUCCESS ]
then
echo "client $client passowrd of oracle updated succesfully!"
echo "$client $password">>success.list
else
echo "Error occurred when updating the password of oracle for client $client"
echo "$client failure">>failure.list
fi
done
----------------------------------------------------------------------------------
10.
用sqlplus spool方法将表数据存入两个文件employee1.txt,employee2.txt
文件output1.sql的内容为:
set head off
set headsep off
set newp none
set linesize 100
set pagesize 10000
set sqlblanklines off
set trimspool on
set termout off
set feedback off
spool employee1.txt
select id||' '||email from employee1;
spool off
exit
然后在命令行将表数据从远程数据库192.168.3.7存入employee1.txt(对于employee2表操作方法相同):
#!/bin/bash
sqlplus -S myuser/mypass@//192.168.3.7:1521/dbFirst @output1.sql
sqlplus -S myuser/mypass@//192.168.3.7:1521/dbSecond @output2.sql
awk 'print $1' employee1.txt>>employee1_id.txt
awk 'print $2' employee1.txt>>employee1_email.txt
awk 'print $1' employee2.txt>>employee2_id.txt
awk 'print $2' employee2.txt>>employee2_email.txt
sort -n employee1_id.txt employee2_id.txt|uniq -u>different_id.txt
sort employee1_email.txt employee2_email.txt|uniq -u>different_email.txt
|
|