Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

perl one liner with -F special char

by LanceDeeply (Chaplain)
on Apr 21, 2005 at 16:54 UTC ( [id://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 (Patriarch) 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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 15:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found