0

I have the following code:

int val

nameof_function();

above code is in this file filename.txt I try to find that sequence of lines in a file using

grep "int val.*\n.*(" filename.txt

but it is not working with multiple line.

I have also tried

awk '/int val/,/\(/' filename.txt 

Here i am not getting file name in output

If I am using grep I can find file name in output but not ble to search muliple line

I need an output that looks like this:

filename.txt:int val nameof_function

Please any one help me

vicky
  • 1
  • 1
  • Fix formatting and reword your question - it's hard to say what are you asking about. – Arkadiusz Drabczyk Jan 30 '20 at 12:52
  • i need to grep pattern with multiple line @Arkadiusz – vicky Jan 30 '20 at 12:56
  • or awk with file name – vicky Jan 30 '20 at 12:57
  • Personally I'd use `pcregrep` with the `-M` switch - however if that's not an option, see [Searching match of multi-line regex in files (without pcregrep)](https://unix.stackexchange.com/questions/449039/searching-match-of-multi-line-regex-in-files-without-pcregrep). You can access the current filename in `awk` using the `FILENAME` builtin variable. – steeldriver Jan 30 '20 at 13:00
  • I tried to edit your post in a way that is more easy to understand, but ultimately it remains unclear e.g. what you mean by "Here i am not getting file name". Also, are you sure that the input is correct? It looks like C, but the `int val` statement is not terminated with a `;` for example. – AdminBee Jan 30 '20 at 13:01
  • i need to search for all directory that time i need file name and the function @steeldriver – vicky Jan 30 '20 at 13:24
  • please check now i have edited @AdminBee – vicky Jan 30 '20 at 13:25
  • Ok, now I understand the problem very well. Thank you. – AdminBee Jan 30 '20 at 13:30

1 Answers1

0

if the source files contain the function separate by a line all you need to do is adjust the output of grep so it finds the int val and output the content 2 lines below also.

it would be something like this

grep -A 2 "int val" *.txt
BANJOSA
  • 701
  • 3
  • 14
  • Before ( symbol o need the value .. I can't go for two line .it will be bigger work .any other way for upto particularly take value with directors.@banjosa'a – vicky Jan 30 '20 at 15:26