![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| bash. convert mpeg adts to normal mp3 | stahoo23 | Shell Programming and Scripting | 6 | 03-13-2009 05:44 AM |
| Help! Need to convert bash shell to perl | freak | Shell Programming and Scripting | 0 | 06-19-2008 11:42 AM |
| Intern needing to convert bash to perl. | freak | UNIX for Dummies Questions & Answers | 0 | 06-17-2008 10:41 AM |
| passing variable from bash to perl from bash script | arsidh | Shell Programming and Scripting | 10 | 06-04-2008 01:25 PM |
| Convert bash to sh URGENT :( | Chris Jones | Shell Programming and Scripting | 2 | 04-18-2004 08:18 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
***convert from perl to bash***
can any body translate the follwing script into one that works in bash?
#!/usr/bin/perl # classify_books.pl my $csv_file = shift; my %categories = ( 'childrens' => 'childrens_books.txt', 'horror' => 'horror_books.txt', 'sports ' => 'sports_books.txt', 'computing' => 'computing_books.txt'); my @childrens_file, @horror_file, @sports_file, @computing_file; open(CSV_FILE, '<', $csv_file) or die "Failed to read file $csv_file : $! \n"; while (my $line = <CSV_FILE>) { next unless ($line =~ m/^\d{3}-\d+,/); my ($isbn, $title, $author, $category) = split(/,/, $line); $title =~ s/^\s+//; $author =~ s/^\s+//; $category = lc($category); $category =~ s/^\s+//; unless (exists($categories{$category})) { print STDERR "\nUndefined category $category for book $title by $author having ISBN $isbn \n"; next; } if ($category =~ m/childrens/) { push(@childrens_file, "ISBN: $isbn\nAuthor: $author\nTitle: $title\n\n"); } elsif ($category =~ m/horror/) { push(@horror_file, "ISBN: $isbn\nAuthor: $author\nTitle: $title\n\n"); } elsif ($category =~ m/sports/) { push(@sports_file, "ISBN: $isbn\nAuthor: $author\nTitle: $title\n\n"); } elsif ($category =~ m/computing/) { push(@computing_file, "ISBN: $isbn\nAuthor: $author\nTitle: $title\n\n"); } } close(CSV_FILE); if (@childrens_file) { open (CHL_FILE, '>', $categories{'childrens'}) or die "Failed to write file $categories{'childrens'} : $! \n"; print CHL_FILE @childrens_file; close (CHL_FILE); } if (@horror_file) { open (CHL_FILE, '>', $categories{'horror'}) or die "Failed to write file $categories{'horror'} : $! \n"; print CHL_FILE @horror_file; close (CHL_FILE); } if (@sports_file) { open (CHL_FILE, '>', $categories{'sports'}) or die "Failed to write file $categories{'sports'} : $! \n"; print CHL_FILE @sports_file; close (CHL_FILE); } if (@computing_file) { open (CHL_FILE, '>', $categories{'computing'}) or die "Failed to write file $categories{'computing'} : $! \n"; print CHL_FILE @computing_file; close (CHL_FILE); } __END__ |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|