Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Copy rows of file to new document

by nagalenoj (Friar)
on Jan 24, 2013 at 09:19 UTC ( #1015112=note: print w/ replies, xml ) Need Help??


in reply to Copy rows of file to new document

If you are using linux machine. You've been already blessed with grep command.

Something like,

grep -rE "(make|model|year)" dir/
Filter top 30 lines as given in tmharish's reply with xargs and head.


Comment on Re: Copy rows of file to new document
Download Code
Replies are listed 'Best First'.
Re^2: Copy rows of file to new document
by phineas629 (Novice) on Jan 25, 2013 at 03:33 UTC

    My folder of files is 'c:\vehicles'. The file I want to write to is 'vehicles.txt' and located in 'c:\'. I tried the following code work for what you suggested. I know I've written it wrong. What should I do to correct it?

    C:\vehicles $ ls -A | xargs head -qn 30 | perl -Mstrict -wne 'if( $ + +_ =~ /(make)|(model)|(year)/ ) { print "$_"; }' > vehicles.txt grep -rE "(make|model|year)" c:

      What is $ +_? Do you mean $_?

      If so, then you can omit it and use just: 'if( /(make)|(model)|(year)/ ) { print "$_"; }'.

      Whether that fixes all your problems I doubt; but its one less to deal with.


      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".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      Only works on Linux

        What if I have cygwin?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2015-08-29 09:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The oldest computer book still on my shelves (or on my digital media) is ...













    Results (343 votes), past polls