Sunday, February 6, 2011

PERL Use '-e' '-F' '-a' '-n' options. Perl One Liners

perl -e 'print "Hello World\n";'
perl -e 'print "Hello World\n"; print "Today is Sunday\n";'
perl -e '$PROD="Linux"; $VERSION="\nversion1"; print "\n$PROD $VERSION";'
perl -e '"\t"';
perl -ne 'print "$_";' data1 #This command prints all the lines from data1 file. -n option makes iterations like while 
perl -ane 'print "$F[0]";' data1 # This prints the first column from a file. -a performs autospliting
perl -ane 'print "@F[0..1]";' data1
awk '{ print $1,$2}' data1 # prints the first 2 columns from the file data1
perl -F: -ane 'print "@F";' /etc/passwd #Prints ll elements from /etc/passwd without delimiter. -F: - change delimeter to ':'
perl -F: -ane 'print "$F[0]";' /etc/passwd # prints the first column that is the users without new line
perl -F: -ane 'print "$F[0]\n";' /etc/passwd # prints the first column that is the users with new line
perl -F: -ane 'print "@F[0..2]";' /etc/passwd # returns the first 3 columns from the file

No comments:

Post a Comment