Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Merge and split files based on number of lines

by Eily (Monsignor)
on Jan 29, 2019 at 13:22 UTC ( [id://1229115]=note: print w/replies, xml ) Need Help??


in reply to Merge and split files based on number of lines

I think you are looking for the -n (or -p) option? It will execute the perl code (generally a oneliner with -E, but it can also work with a file) over each line of each file passed as an argument, and sets $_ to the content of the line. If you use the -n option you have to print whatever output you need yourself, with the -p option it prints the (possibily modified) content of $_ after each line. The variable $ARGV contains the name of the currently processed file.

Eg: perl -nE 'say "$ARGV: $_" if /Valid/' file1 file2 file3
will print all the lines from each three files that contain "Valid".

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-19 19:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found