Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

perl one liner with -F special char

by LanceDeeply (Chaplain)
on Apr 21, 2005 at 16:54 UTC ( #450101=perlquestion: print w/replies, xml ) Need Help??

LanceDeeply has asked for the wisdom of the Perl Monks concerning the following question:

i'm trying to print the unique keys of a datafile.
my key indexes are 0,1,2,3 and my delimiter is ^
4363^7619082^309839685^309841122^14^18 4363^7619082^309839685^309841122^14^19 4363^7619082^309839685^309841122^14^20 4363^7619082^309839685^309841122^26^25 4363^7619082^309839685^309841122^26^26 4363^7619082^309839685^309841122^14^52 4363^7619082^309839685^309841122^14^51 4363^7619082^309839685^309841122^23^21
this code works:
perl -ne '@ar = split /\^/; $key="$ar[0],$ar[1],$ar[2],$ar[3]\n"; pri +nt $key if ( ! $seen{$key} ++ );' datafile
but i want to use -F like so:
perl -naF^ -e '$key="$F[0],$F[1],$F[2],$F[3]\n"; print $key if ( ! $se +en{$key} ++ );' datafile or -F/^/ -F/\^/ -F"^" -F'^'
but it wont split!
any suggestions?

Replies are listed 'Best First'.
Re: perl one liner with -F special char
by cog (Parson) on Apr 21, 2005 at 16:58 UTC
    -F"\^"
      thanks everyone!
      i thought i tried every combination
Re: perl one liner with -F special char
by sk (Curate) on Apr 21, 2005 at 17:08 UTC
    This might be easy for you remember.

    Whatever you are using in your split use it in your -F as is

    for example

    perl -naF"/\^/" -e '$key="$F[0],$F[1],$F[2],$F[3]\n"; print $key if ( +! $seen{$key} ++ );' datafile 4363,7619082,309839685,309841122
    Notice the -F uses whatever is in your split.

    Update: Please quote your param for F switch as you don't want the shell to interpret your backslashes.

Re: perl one liner with -F special char
by ikegami (Pope) on Apr 21, 2005 at 17:02 UTC
    How about -F"\^"?
    >perl -lnaF"\^" -e "print $F[0]"
    works for me. So does this:
    >perl -lnaF\136 -e "print $F[0]"
Re: perl one liner with -F special char
by deibyz (Hermit) on Apr 21, 2005 at 17:20 UTC
    Seems shell doing *its work*.
    This works for me:

    perl -anF'\136' -e '$key="$F[0],$F[1],$F[2],$F[3]\n"; print $key if ( +! $seen{$key} ++ );' datafile

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://450101]
Approved by ghenry
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2021-05-14 06:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (149 votes). Check out past polls.

    Notices?