Text Formatting Perl Script
Here is a pretty basic Perl script that will take a tab seperated file and format it accoring to the arguments you pass with the command. This script will only work if the file has three fields, but can be edited for more. I am working on a way to unlimit this using arrays, but have not found a working solution yet. Also, this script is protable to windows. Just edit the environment path to reflect where your perl executable is located. Code below:
#!/usr/bin/perl -w
#
#text2pretty.pl
#written by trizsolo
#
#:usage:: ./text2pretty.pl
my $ugly_file = shift;
if(!defined $ugly_file){
print "Usage: $0 optional \n";
exit;
}
open(FILE, $ugly_file);
while(){
chomp;
# if (/!! Start !!/ .. /!! End !!/) { #Uncomment this line to process certain part of file#
# if (1..10); #Uncomment this line to process certain concecutive lines#
($field1, $field2, $field3)=split("\t");
print "$ARGV[0]: $field1\n";
print "$ARGV[1]: $field2\n";
print "$ARGV[2]: $field3\n";
print "---------\n";
# }
}
close(FILE);
exit;
So a text file like this…
bigboi 4492 texas
lilmama 4677 alaska
sugamama 9755 Cali
Will print out like this when you run the command as follows:
./text2pretty.pl test.txt Name SSN Loc
Name: bigboi
SSN: 4492
Loc: texas
---------
Name: lilmama
SSN: 4677
Loc: alaska
---------
Name: sugamama
SSN: 9755
Loc: Cali
---------