it is a very simple task to exercise your understanding of the perl language.
the issue is like this :
$ cat test.txt
a,1,x,A,B,C
b,2,y,D
c,3,z,E,F
and you want to display the final result as follow.
a,1,x,A
a,1,x,B
a,1,x,C
b,2,y,D
c,3,z,E
c,3,z,F
Below shows some techinques.
perl -F, -lane '$k=3;for $f (@F[$k..$#F]) { print join(",", @F[0..$k-1]), ",$f" }' test.txt
and you can also write the following script files.
#! /bin/perl # you may also run the following command on the command line, # perl -F, -lane '$k=3;for $f (@F[$k..$#F]) { print join(",", @F[0..$k-1]), ",$f" }' test.txt while (<STDIN>) { while ($_ =~ /^([a-z0-9,]+)?([A-Z0-9,]+)/g) { map {print "$1$_\n" } split (/,/, $2) ; } }
or
#! /bin/perl # you may also run the following command on the command line, # perl -F, -lane '$k=3;for $f (@F[$k..$#F]) { print join(",", @F[0..$k-1]), ",$f" }' test.txt $k = 3; while (<>) { @F = split(",", $_); for $f (@F[$k..$#F]) { print join(",", @F[0 .. $k - 1]), ",$f\n"; } }
Or you can do this following line as well.
$ perl -F, -lane '($a,$b,$c,@o) = @F; print "$a,$b,$c,$_" for (@o); '
相关推荐
离线安装包,亲测可用
解决MySQL在linux下缺少依赖 perl-Pod-Simple-3.13-141.el6_7.1.x86_64.rpm
perl-HTTP-Server-Simple,perl的扩展包,perl的扩展包
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
strawberry-perl-5.32.1.1-64bit.msi离线安装包(官方),可避免从官网下载速度慢的问题。 windows环境的perl安装包,不用去官网下载了,测试好用。 strawberry-perl-5.32.1.1-64bit.msi离线安装包(官方),可避免...
linux 离线安装perl-IPC-Cmd
strawberry-perl-5.32.1.1-32bit.msi离线安装包(官方),可避免从官网下载速度慢的问题。 windows环境的perl安装包,不用去官网下载了,测试好用。 strawberry-perl-5.32.1.1-32bit.msi离线安装包(官方),可避免...
perl-WWW-Curl4.17版本rpm包
装mysql时提示少perl,安装perl需要依赖包。...1:perl-Pod-Simple-3.28-4.el7.noarch perl-Getopt-Long-2.40-2.el7.noarch 4:perl-5.16.3-286.el7.x86_64 kernel-devel-3.10.0-327.10.1.el7.x86_64
ActivePerl-5.28.1 win10 x64离线安装包(官方),可避免从官网下载速度慢的问题。 ActivePerl-5.28.1 win10 x64离线安装包(官方),可避免从官网下载速度慢的问题。 ActivePerl-5.28.1 win10 x64离线安装包(官方...
Perl-5.10.0版本,Perl-5.10.0版本,Perl-5.10.0版本,Perl-5.10.0版本,Perl-5.10.0版本,Perl-5.10.0版本,Perl-5.10.0版本,Perl-5.10.0版本,Perl-5.10.0版本,Perl-5.10.0版本,Perl-5.10.0版本,Perl-5.10.0...
strawberry-perl-5.10.1.0.msi
Windows Perl-5.36.0 VC2017 源码编译版 此版本是在Windows下,使用github上Perl-5.36的源码,在VC2017下编译的。
Digest-Perl-MD5
perl-MailTools-1.53-1.noarch.rpm
刚刚下载的strawberry-perl-5.32.1.1-64bit 用于64位系统Perl 希望对你有用
perl-DBD-MySQL-4.013-3.el6.x86_64.rpm
perl-DBI-1.52-2.el5.i386.rpm
perl-5.16.3-297.el7.x86_64.rpm
Windows Perl-5.36.0 VC2015 源码编译版 此版本是在Windows下,使用github上Perl-5.36的源码,在VC2015下编译的。