Hi all...
Is there any solution to do the reverse process of getline ?
Thanks in advance.
Hi all...
Is there any solution to do the reverse process of getline ?
Thanks in advance.
Why not only save line to variable ?
{
# save current line for later using
prev=$0
}
If need previous line, you can use variable or return it to the variable $0
{ # some rule
# save current for later using
curr=$0
# take previous line
$0=prev
# do something
...
# and return current line
$0=curr
}
Thanks a lot...
Prints line before pattern
awk '/pattern/ {print a}{a=$0}'
Hi Jotne,
Could you please explain the code?
Thanks!
awk '
/pattern/ {print a}
{a=$0}'
Running on a file:
Line1: Does it contain "pattern", yes print a (here a will be empty), no continue
a=Line1
Line2: Does it contain "pattern", yes print a (her a contial line1), no continue
a=Line2
Line3: Does it contain "pattern", yes print a (her a contial line2), no continue
a=Line3
So a does always contain previous line.