Program

I am trying to write a program that would read this file

A 11 PROK:File 001 Mes amis, Mes amies
La vie
philo 1 gr 056 am 145 co 0 aile2
niveau 2, txt 001 La vida ID 2, da VI 2100

A 12 PROK:File 001 Mes freres, Mes soeurs
La servitude
philo 1 gr 006 am 145 co 0 aile12
niveau 1, txt 011 La vida ID 2, da VI 2100

A 13 PROK:File 001 Mes freres, Mes soeurs
La servitude
philo 1 gr 006 am 145 co 0 aile2
niveau 1, txt 011 La vida ID 2, da VI 2100

and return the value for only aile2.

Let's say I call this file: TestFile

I tried the following and it did not work.

while read file
do
printf "$aile2"
done < FileList

Can anyone tell me what the correct code is?

Thanks!

cat file | grep "aile"

will provide the two lines where "aile" exists:
philo 1 gr 056 am 145 co 0 aile2
philo 1 gr 006 am 145 co 0 aile2

Are you looking for something on those two lines, or from elsewhere in each of those datablocks?

Actually, this command only gives me the lines that contain aile 2. I am trying rather to capture the values of "aile 2" i.e all the lines that come after "aile 2" including the lines with aile "2".

Thank you for the reply!!!

Please review/verify:

Always four lines of data
Third line may contain "aile2"
If so, then
  Report that third line and the following (fourth) line
  export this to a new file

Yeah, the idea is right. The file however can have more than 4 lines. As you said, if a line contains aile, then print all the lines that follow will work.

Note. Sometimes I have a huge file that has info for 100 ailes, but I just want to retrieve the info for a specific aile.

The original example showed:
philo 1 gr 056 am 145 co 0 aile2
niveau 2, txt 001 La vida ID 2, da VI 2100

But, you said there could be additional lines. If more lines, how would program know that it has reached the end of the section? By two consecutive <CR><LF> entries?

Up to how many lines could be included?
Is there any pattern to these?

There should be a way to tell the program to read the lines that come after the "line with aile 2" regardless of how many lines there are. But, for the sake of this conversation, let's say there 8 more lines.

philo 1 gr 056 am 145 co 0 aile2
niveau 2, txt 001 La vida ID 2, da VI 2100
niveau 3, txt 001 La vida ID 3, da VI 3200
niveau 4, txt 001 La vida ID 4, da VI 4300
niveau 5, txt 001 La vida ID 5, da VI 5400
niveau 6, txt 001 La vida ID 6, da VI 6500
niveau 7, txt 001 La vida ID 7, da VI 7600
niveau 8, txt 001 La vida ID 8, da VI 8700
niveau 9, txt 001 La vida ID 9, da VI 9800

until find a blank line?

Could be 1-8 (or more) lines of info. But, the key break in data would be a blank line.

What is the code then?

ailed is the input file based on your first message

awk 'BEGIN {RS=""} /aile2/' ailed

gives:

A 11 PROK:File 001 Mes amis, Mes amies
La vie
philo 1 gr 056 am 145 co 0 aile2
niveau 2, txt 001 La vida ID 2, da VI 2100
A 13 PROK:File 001 Mes freres, Mes soeurs
La servitude
philo 1 gr 006 am 145 co 0 aile2
niveau 1, txt 011 La vida ID 2, da VI 2100

Is that what you are looking for?

It works.

Thanks!!!