Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Access and modify specific element of tab delimited .txt file

by BrowserUk (Patriarch)
on Mar 30, 2016 at 11:16 UTC ( [id://1159100]=note: print w/replies, xml ) Need Help??


in reply to Access and modify specific element of tab delimited .txt file

Is there a way to print something into this first element?

I suspect you're after something more complex, but on the face of it, this seems to answer that question:

C:\test>type junk.dat A B C D E A 1 1 1 1 1 B 1 1 1 1 1 C 1 1 1 1 1 D 1 1 1 1 1 E 1 1 1 1 1 C:\test>perl -plae" $.== 1 and $F[0] eq 'A' and $_ = 'ID' . $_" junk.d +at ID A B C D E A 1 1 1 1 1 B 1 1 1 1 1 C 1 1 1 1 1 D 1 1 1 1 1 E 1 1 1 1 1

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Access and modify specific element of tab delimited .txt file
by K_Edw (Beadle) on Mar 30, 2016 at 12:24 UTC

    Thanks! This works well (after replacing " with '). It is slightly more complex in that $F[0] will not always eq 'A', so this could also be used:

    perl -plae '$.== 1 and $_ = 'ID' . $_'
      Is there a way for it to simply check for any string (non-delimiter character) at all?

      Eily called it right:

      C:\test>type junk.dat A B C D E A 1 1 1 1 1 B 1 1 1 1 1 C 1 1 1 1 1 D 1 1 1 1 1 E 1 1 1 1 1 C:\test>perl -F\t -plae"$.== 1 and $F[0] eq '' and $_ = 'ID' . $_" jun +k.dat ID A B C D E A 1 1 1 1 1 B 1 1 1 1 1 C 1 1 1 1 1 D 1 1 1 1 1 E 1 1 1 1 1

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (1)
As of 2026-05-11 18:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.