sed/awk与unix命令等价代码[转]

网友投稿 788 2022-09-25

sed/awk与unix命令等价代码[转]

sed/awk与unix命令等价代码[转]

转自: chinaunix- 特此感谢

sed与unix 命令等价代码

特此感谢转贴者:admirer

-------------------------------------------------------------------------------

cat |sed ':'

cat -s | sed '/./,/^$/!d'

tac | sed '1!G;h;$!d'

grep | sed '/patt/!d'

grep -v | sed '/patt/d'

head | sed '10q'

head -1 | sed 'q'

tail | sed -e ':a' -e '$q;N;11,$D;ba'

tail -1 | sed '$!d'

tail -f | sed -u '/./!d'

cut -c 10 | sed 's/(.).*/1/'

cut -d: -f4 | sed 's/(([^:]*):).*/2/'

tr A-Z a-z | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'

tr a-z A-Z | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'

tr -s ' ' | sed 's/ +/ /g'

tr -d '12' | sed 'H;$!d;g;s/n//g'

wc -l | sed -n '$='

uniq | sed 'N;/^(.*)n1$/!P;D'

rev | sed '/n/!G;s/(.)(.*n)/&21/;//D;s/.//'

basename | sed 's,.*/,,'

dirname | sed 's,[^/]*$,,' xargs | sed -e ':a' -e '$!N;s/n/ /;ta'

paste -sd: | sed -e ':a' -e '$!N;s/n/:/;ta'

cat -n | sed '=' | sed '$!N;s/n/ /'

grep -n | sed -n '/patt/' | sed '$!N;s/n/:/'

cp orig new | sed 'w new' orig[/code:1:739eb4cef5]

-------------------------------------------------------------------------------

awk与unix 命令等价代码

特此感谢作者:飞灰橙

------------------------------------------------------------------------------

cat |awk ''

cat -s |awk '{blank = NF == 0 ? ++blank : 0; if (blank tac |awk '{t[NR] = ;}END{for (i = NR; i >= 1; i--) print t[i];}'

grep patten |awk '/patten/'

grep -v patten |awk '! /patten/'

head |awk 'NR head -1 |awk '{print; exit; }' 24.sh

tail |awk '{t[n++ % 10] = }END{for (i = 0; i <10 print> tail -1 |awk '{t = }END{print t}'

cut -c 10 |awk '{print substr(, 10, 1)}'

cut -d: -f4 |awk -F: '{if (NF > 1) print ; else print;}'

tr A-Z a-z |awk '{print tolower();}' se.sh

tr a-z A-Z |awk '{print toupper();}' se.sh

tr -s ' ' |awk '{print gensub(" +", " ", "g")}'

tr -d '12' |awk '{printf "%s", }'

wc -l |awk 'END{printf "% 7dn", NR-1}'

uniq |awk '{if (NR == 1 || ln != ) print; ln = ;}'

rev |awk '{l = ""; for (i = length(); i > 0; i--) printf "%c", substr(, i, 1); print "";}'

basename |awk -F'/' '{print $NF}'

dirname |awk -F'/' '{if (NF xargs |awk '{printf "%s ", }END'

paste -sd: |awk 'NR > 1{printf "s", }'

cat -n |awk '{printf "% 6d %sn", NR, }'

grep -n |awk '/ss/{print NR":"}'

cp orig new |awk '{print > "new"}' orig

-------------------------------------------------------------------------------

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:12强赛收官战,国足重点研究阿曼角球战术!(国足绝杀阿曼)
下一篇:SED,AWK学习笔记Part 1-----利用正则表达式进行文本匹配[转]
相关文章

 发表评论

暂时没有评论,来抢沙发吧~