I realize this has been asked many times and many of the answers seam well written, but I'm missing something with my little task. Trying to pass a Shell variable (an argument in this case) to awk to grab a section of a text file out.
cat ~/work/junk.txt
[Section1]
innerline1
innerline2
innerline3
[Section2]
innerline4
innerline5
innerline6
I'm trying to make a script to use the provided argument ($1) to pass as the pattern to match in awk.
#!/bin/bash
echo pattern is $1
# record separator (RS) is the next blank line
awk -v var="$1" {print '/var/'} RS= ~/work/junk.txt
If $1 is the argument provided as "Section1" I expect this output:
[Section1]
innerline1
innerline2
innerline3
I think I'm close, but yet so very far.
Thanks for any ideas.