LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1099|回复: 8

复制文件中的每行(sed)

[复制链接]
发表于 2004-8-15 15:42:47 | 显示全部楼层 |阅读模式
有文件a如下:
-------------------------------------------
my world,is bright
my friend, is beautiful
my father,is good
-------------------------------------------
现在欲把a变成如下:
-------------------------------------------
my world,is bright
my world,is bright
my friend, is beautiful
my friend, is beautiful
my father,is good
my father,is good
-------------------------------------------
我是用sed来实现的,命令行如下:
sed -e 's/\(^.*$\)/\1\n\1/' a
如果,想用awk实现,如何实现,谢谢了先。
:p
发表于 2004-8-15 15:47:38 | 显示全部楼层
  1. sed '1,$p' file
复制代码
 楼主| 发表于 2004-8-15 16:46:35 | 显示全部楼层
呵呵,Lee兄,这个倒是很简单。^_^
可是,如果要复制的不止一行,而是二行,这个脚本似乎不能满足要求。
:p
发表于 2004-8-15 17:43:34 | 显示全部楼层
esay:

  1. cat file|while read i;do
  2.     i=1
  3.     while((i<=3));do
  4.         echo $i;((i+=1))
  5.     done
  6. done
复制代码

awk:

  1. awk '{i=1;while(i<=3){print;i++}}' file
复制代码
发表于 2004-8-16 08:28:49 | 显示全部楼层
复制一次sed '1,$p' file
复制两次sed '1,${p;p}' file
复制三次sed '1,${p;p;p}' file
发表于 2004-8-16 08:50:42 | 显示全部楼层
敢问KornLee兄,esay是什么东东?
谢谢
发表于 2004-8-16 08:55:21 | 显示全部楼层
我也来一个:
  perl: a.pl
         源码:
---------------------------------------
           #!/usr/bin/perl -w
           while (<>) {
              print $_ x 2;
           }
-----------------------------------------
run it as : ./a.pl a
发表于 2004-8-16 10:55:56 | 显示全部楼层
sed 'p' file 即可
发表于 2004-8-16 20:40:33 | 显示全部楼层

晕~~

cat xx xx | sort > yyy

simple is best!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表