리눅스 a2p

1 개요[ | ]

Awk to Perl translator
리눅스 a2p
/usr/bin/a2p
  • awk 스크립트를 perl 스크립트로 변환하는 리눅스 명령어

2 실습[ | ]

[root@zetawiki ~]# cat wc.awk
#!/bin/awk -f
{
    w += NF
    c += length + 1
}
END { print NR" lines, "w" words, "c" charaters" }
[root@zetawiki ~]# ./wc.awk /etc/issue
3 lines, 9 words, 47 charaters
[root@zetawiki ~]# a2p wc.awk
#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
    if $running_under_some_shell;
			# this emulates #! processing on NIH machines.
			# (remove #! line above if indigestible)

eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_0-9]+=)(.*)/ && shift;
			# process any FOO=bar switches

$[ = 1;			# set array base to 1
$, = ' ';		# set output field separator
$\ = "\n";		# set output record separator

while (<>) {
    chomp;	# strip record separator
    @Fld = split(' ', $_, -1);

    $w += $#Fld;
    $c += length($_) + 1;
}

print $. . ' lines, ' . $w . ' words, ' . $c . ' charaters';
→ 변환된 결과(perl 스크립트 내용)가 화면에 출력됨
[root@zetawiki ~]# a2p wc.awk > wc.pl
[root@zetawiki ~]# chmod 755 wc.pl
[root@zetawiki ~]# ./wc.pl /etc/issue
3 lines, 9 words, 47 charaters
→ 파일로 저장하여 실행하니 결과가 동일함

3 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}