LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to use "awk" to do the following seemingly simple work? (https://www.linuxquestions.org/questions/linux-software-2/how-to-use-awk-to-do-the-following-seemingly-simple-work-635916/)

lawrence_lee_lee 04-17-2008 03:28 AM

How to use "awk" to do the following seemingly simple work?
 
1) Given an input file, I want to perform some action to a line subject to some conditions of the next line. For example,

if the next line is "======" then I want to print the current line.
How can such actions be performed using awk?

2) Is there any method for awk to go back one/more line(s) when reading a file?

3) What is the difference between these two intrinsic variables: NR and FNR?

4) Does awk support multidimensional array?

Tinkster 04-17-2008 04:29 AM

Quote:

Originally Posted by lawrence_lee_lee (Post 3123865)
2) Is there any method for awk to go back one/more line(s) when reading a file?

No.

Quote:

Originally Posted by lawrence_lee_lee (Post 3123865)
1) Given an input file, I want to perform some action to a line subject to some conditions of the next line. For example,

if the next line is "======" then I want to print the current line.
How can such actions be performed using awk?

Store each line in a transient buffer, compare to current and
print it.

Quote:

Originally Posted by lawrence_lee_lee (Post 3123865)
3) What is the difference between these two intrinsic variables: NR and FNR?

NR is the TOTAL number of records seen, FNR pertains
to the "current file".

Quote:

Originally Posted by lawrence_lee_lee (Post 3123865)
4) Does awk support multidimensional array?

Yes.



Cheers,
Tink


All times are GMT -5. The time now is 01:52 AM.