Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8146179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:54:34+00:00 2026-06-06T13:54:34+00:00

I have been using grep with perl extension for multiline match .However it turns

  • 0

I have been using grep with perl extension for multiline match .However it turns out that the line number of all the match depends on the number of lines in the first multiline match !

The grep regex to find the c function start :

   grep -iPn '^[^\S\n]*?\w+\s+\w+?\s*\([\w-0-9,/* \s]*\)\s*\{$'

I can explain better with an example :

Suppose these two function exists in the source file

      int f1(int a) {       

      int 
      f2 (int b )        
      {

In this case ,the grep matches the regex successfully and the line number output to stdout is in par with the line number of the source file .

The problem arises when a multiline function comes first .This alters the line number output and after examining the file for some time I came to a conclusion. The multiline functions are matched but read as a single line by the grep therefore it assigns the whole function a single line number.The next line that follows the function gets its line number short depending on the number of lines the ‘function definition start regex ‘occupies.

There are numerous multiline C functions in my file and the line number is way too deviated for each one of them.

Is there a way to correct this ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T13:54:36+00:00Added an answer on June 6, 2026 at 1:54 pm

    Using the pcregrep for the same regex shows the correct line number !

     pcregrep -Mni '^[^\S\n]*?\w+\s+\w+?\s*\([\w-0-9,/* \s]*\)\s*\{$'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using this so far system 'strings binary-file.dmp | grep search_string' Is
I have been using this code with great success to pull out the first
I have been using the 'Web Site Administration Tool' that you can bring up
I have been using attachment_fu on a project for a long time and all
I have a method that performs a simplistic 'grep' across files, using an enumerable
I've been using the following command to grep for a string in all the
I have a .vimrc file that contains the following line: syntax match proper /\s[A-Z][a-zA-Z]*/
Ive been trying to sort out output using AWK, and have been pretty successful
I have been using Visual Studio integrated with Source Safe for years, when I
I have been using the CodeIgniter system for a while now - but it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.