Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello,
i've to read option between two points, like that :
[AA]
option1 = text
option2 = text
[/AA]i don't know read text which is multiline, i only read text between two points...but on the same line .
thank you,
Max

Max:
It sounds like you need to use a range pattern either in sed or awk. Since your begin flag is [AA] and your end flag is [/AA]
you have to ecape with a \, the special characters [ ] /
sed -n "/\[AA\]/,/\[\/AA\]/p" data.fileor
awk ' /\[AA\]/,/\[\/AA\]/ ' data.file
Regards,
Nails

Those range searches come in handy. But they include the beginning and ending lines that contain the patterns. When you want only what is in between, you need more work. Another warning is that both sed and awk will start printing a group not knowing if it will be terminated by the end range or not.
The following awk solution will print only what is in between your range lines, and I took the easy road and hard-coded the search patterns. Like awk and sed, it starts printing not knowing if it will reach an end-range line or not.
awk '{\
if (inprog==1)
if (match($0,"\[/AA\]"))
inprog=0 # or "exit" at end of first group
else
else
if (match($0,"\[AA\]"))
inprog=1
}' data.fileAs coded, like the awk and sed range search, it will process as many groups as it finds in the file, but if you want it to quit after printing the first group, just change the inprog=0 statement to exit.

![]() |
How to change IPs in SCO ...
|
printer emulation
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |