Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

add text to each line of a file

by stevenrh (Beadle)
on Mar 10, 2005 at 19:19 UTC ( [id://438392]=CUFP: print w/replies, xml ) Need Help??

this might not even be cool, but it started as a "I bet you can't do that as a a one-liner" from a cow-worker.

we wanted to turn our usernames into email addresses for our domain, from the NIS database.
It isn't entirely in perl, but it is pretty useful for me :)

ypcat passwd | awk -F: '{print $1}' | perl -p -e' ; chomp; print "$_\@ +domain.local > oneliner.out

hope this helps someone else out there....
stevenrh

Replies are listed 'Best First'.
Re: add text to each line of a file
by thor (Priest) on Mar 10, 2005 at 19:30 UTC
    What about
    ypcat passwd | perl -F: -lane 'print "$F[0]\@domain.local"' > oneliner +.out
    ? :-)

    thor

    Feel the white light, the light within
    Be your own disciple, fan the sparks of will
    For all of us waiting, your kingdom will come

      Why chomp? I belive the -l option chomps the line automatically. (See perlrun.)
        You're absolutely right! I hardly ever use -n or -p, so I forgot about the "other" effect of -l. Thanks!

        thor

        Feel the white light, the light within
        Be your own disciple, fan the sparks of will
        For all of us waiting, your kingdom will come

Re: add text to each line of a file
by b10m (Vicar) on Mar 10, 2005 at 19:36 UTC

    Why use Perl at all?

    ypcat passwd | awk -F: '{ print $1."@domain.local" }' > oneliner.out
    --
    b10m

    All code is usually tested, but rarely trusted.

      Why use awk at all?

      ypcat passwd | perl -wne '/:/ and print "$`\@domain.local\n";'
      or
      ypcat passwd | cut -d: -f1 | sed 's/$/@mydomain.local/'
      or
      ypcat passwd | sed 's/:.*/@domain.local/'
        No! Not the dreaded $` I have trained myself so well to not use them that it now scares me to see it.

        $will->code for @food or $$;

        And to complete the sed:
        ypcat passwd |sed 's/:.*/@domain.local/'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://438392]
Approved by b10m
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (1)
As of 2024-04-24 14:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found