reading a text file and passing to a script

Hi,
I am lost and no sure the best way way to go

I have a txt file formatted as follows
10999452   Sally Public
11014066   John Doe Public
etc...

I need to read the file and match up the number and preform a command

Command as follows


EXAMPLE
user_export -txv -R 10999452  -o "/nfs/10/Sally Public.tar"
user_export -txv -R 11014066  -o "/nfs/10/John Doe Public.tar"

The user_export is a complied program which I do not have the source code for and I must use the -txv -R .

Thanks for your assistance !
jjcheap1Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Something like this will do...

#
!/usr/bin/env perl

use strict;
use warnings;

while (my $rec = <STDIN>) {
    chop $rec;
    my ($id,$name) = split \s+/, $rec, 2;
    my $cmd = "user_export -txv -R $id  -o '/nfs/10/$name Public.tar'";
    print $cmd, "\n";
    system($cmd);
}

Open in new window


Just typed this off the top of my head, so might require some refinement.

You get the general idea.
jjcheap1Author Commented:
Hi David,

Thanks for your assistance

I named the script as get.pl and chmod 755

users.txt
10993854         Cathy Jane Jones      HR ASSMBY LEAD New Hire      
10993855         Jim A Jones                Stock Room Location BLG A

./get.pl < users.txt

I am getting Substitution pattern not terminated at ./get.pl line 8.

I have tired to google Substitution pattern not terminated
Any Suggestions?

Thanks!

#!/usr/bin/env perl

use strict;
use warnings;

while (my $rec = <STDIN>) {
    chop $rec;
    my ($id,$name) = split \s+/, $rec, 2;
    my $cmd = "mfs__export -txv -R $id  -o '/nfs/10/$name.tmf'";
    print $cmd, "\n";
    system($cmd);
}
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
As I said, just dashed this off, so change the split to have a pattern of /\s+/.

Also, you're data is variable field, so how you parse this is anyone's guess...

In other words, you never know if a person's name is two fields (Jane Doe) or three fields (Jim A Jones).

Best if you reformat your data where fields are delimited, say with a "," so they're true CSV format file.

This will keep your parsing sensible.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

jjcheap1Author Commented:
Good Morning David,

Thanks for your assistance!  I need to clean up the input file.
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Yes. I think if you simply delimit all your file data, like a standard CSV file, then your code will be far easier to get working.

Be sure to build in testing that data has the correct format too. This way you'll only feed good data to the process you're running.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jjcheap1Author Commented:
Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.