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

matching first paragraph satisfying condition

by mnshptl32 (Initiate)
on Aug 05, 2019 at 16:14 UTC ( [id://11103963]=perlquestion: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    awk -v RS='' -v ORS='\n\n' '/^[^ ].*$/' file.txt | awk -v RS='' 'NR==1
    +{print $0}'
    
  2. or download this
    perl -0pe 's/.*?\n*?([^ \n].*?)\n\n.*/$1/gs' file.txt
    
  3. or download this
    perl -0pe 's/([^ \n].*?)\n\n.*/$1/gs' file.txt
    
  4. or download this
    perl -0pe 's/.*?\n([^ \n].*?)\n\n.*/$1/gs' file.txt
    
  5. or download this
    if ( $. == 1 and /^[^ ].*$/ ) {...}
    
  6. or download this
    echo '' > tempfile.txt ; cat file.txt >> tempfile.txt ; perl ...
    
  7. or download this
    if [[ $(egrep -n -m1 -e '^[^ ]' file.txt | sed 's/^\([0-9]\+\):.*/\1/g
    +') -eq 1 ]] ; then perl ... ; else perl ... ; fi
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-18 03:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found