码迷,mamicode.com
首页 > 其他好文 > 详细

awk 替换练习题

时间:2014-09-19 23:42:36      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   for   div   sp   log   on   c   

练习题:http://blog.chinaunix.net/uid-10540984-id-3086644.html

cat file:

a b c a d a
s d d d x s a
h j s a s h j h
j d f j a s j k j
 
要求:删除行内与第一列字符重复的字符,shell、sed、awk各写一个。达到这个结果:
a b c d
s d d d x a
h j s a s j
j d f a s k

 

awk ‘ {s=$1;printf s;for (i=2;i<=length($0)-1;i++) if($i!=s) printf $i;print ‘\n‘}‘ test.txt

人家的答案:awk ‘{a=$1;gsub(" ?"a,"");print a""$0}‘ file

awk 替换练习题

标签:style   blog   http   for   div   sp   log   on   c   

原文地址:http://www.cnblogs.com/amandaysu/p/3982655.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!