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

Re: Re: very basic, just beginning

by jmanning2k (Pilgrim)
on Aug 27, 2003 at 18:17 UTC ( [id://287124]=note: print w/replies, xml ) Need Help??


in reply to Re: very basic, just beginning
in thread very basic, just beginning

Update: I read the question better & turned down the flame-o-meter on this comment...

This code might get you in trouble if there are newlines in the file. If that is the case then...

It puts "filename.txt" as every other line in the file. The while loop is what gets you in trouble here. Perhaps if you do a undef $/ somewhere in there.

Or, even better, start with your version and test for the first line.

perl -pi -e '$ARGV =~ s/\.txt//; $_=">$ARGV\n$_\n if($.==1)"' *.txt
This adds three things - it removes the .txt from the filename first. Second, it adds the initial '>' character. Finally, it only rewrites the first line. ($. is line number).

Not the most elegant, but it works.

Replies are listed 'Best First'.
Re: Re: Re: very basic, just beginning
by fletcher_the_dog (Friar) on Aug 27, 2003 at 18:25 UTC
    Umm, I said "If each file really is "straight text, no carriage returns, no spaces, etc. " If there are no carriage returns there is only one line. If you are getting the file name every other line than your file has one more than one line and doesn't fit the requirement straight text, no carriage returns, no spaces, etc. Also, no where is it specified to remove the ".txt". In fact the example specifically shows the ".txt" being there
    filename: a36.txt initial filecontents : AATGACGTACGTAGTCGTAGCGT after script filecontents : >a36.txt AATGACGTACGTAGTCGTAGCGT [newline]
      Fair enough... I gave your orig comment a ++ anyway. I didn't realize the original data had no newlines.

Log In?
Username:
Password:

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

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

    No recent polls found