Skip to main content
Need export peak to make peak an environment variable, or "peak=$peak awk ..."
Source Link
Kusalananda
  • 356.2k
  • 42
  • 737
  • 1.1k

Your code:

echo "Enter peak value"
read peak
awk '/${peak}/{c=3}c&&c--' consolelog.log > testing.txt

This does not work because strong quotes prevent the shell from performing variable expansion. This is good because awk uses a lot of syntax that weak quotes would make very difficult to use.

There are, however, ways to use environment variables within an awk script.

You can declare your own variable:

read peak
awk -vpeak="$peak" '$0 ~ peak { c=3 } c&&c--' consolelog.log > testing.txt

Or you can just tell awk to look at the one you just used read to fill:

read peak
export peak
awk '$0 ~ ENVIRON["peak"] { c=3 } c&&c--' consolelog.log > testing.txt

Your code:

echo "Enter peak value"
read peak
awk '/${peak}/{c=3}c&&c--' consolelog.log > testing.txt

This does not work because strong quotes prevent the shell from performing variable expansion. This is good because awk uses a lot of syntax that weak quotes would make very difficult to use.

There are, however, ways to use environment variables within an awk script.

You can declare your own variable:

read peak
awk -vpeak="$peak" '$0 ~ peak { c=3 } c&&c--' consolelog.log > testing.txt

Or you can just tell awk to look at the one you just used read to fill:

read peak
awk '$0 ~ ENVIRON["peak"] { c=3 } c&&c--' consolelog.log > testing.txt

Your code:

echo "Enter peak value"
read peak
awk '/${peak}/{c=3}c&&c--' consolelog.log > testing.txt

This does not work because strong quotes prevent the shell from performing variable expansion. This is good because awk uses a lot of syntax that weak quotes would make very difficult to use.

There are, however, ways to use environment variables within an awk script.

You can declare your own variable:

read peak
awk -vpeak="$peak" '$0 ~ peak { c=3 } c&&c--' consolelog.log > testing.txt

Or you can just tell awk to look at the one you just used read to fill:

read peak
export peak
awk '$0 ~ ENVIRON["peak"] { c=3 } c&&c--' consolelog.log > testing.txt
deleted 4 characters in body
Source Link
DopeGhoti
  • 79.3k
  • 10
  • 107
  • 141

Your code:

echo "Enter peak value"
read peak
awk '/${peak}/{c=3}c&&c--' consolelog.log > testing.txt

This does not work because strong quotes prevent the shell from performing variable expansion. This is good because awk uses a lot of syntax that weak quotes would make very difficult to use.

There are, however, ways to use environment variables within an awk script.

You can declare your own variable:

read peak
awk -vpeak="$peak" '$0 ~ /peak/ { c=3 } c&&c--' consolelog.log > testing.txt

Or you can just tell awk to look at the one you just used read to fill:

read peak
awk '$0 ~ /ENVIRON["peak"]/ { c=3 } c&&c--' consolelog.log > testing.txt

Your code:

echo "Enter peak value"
read peak
awk '/${peak}/{c=3}c&&c--' consolelog.log > testing.txt

This does not work because strong quotes prevent the shell from performing variable expansion. This is good because awk uses a lot of syntax that weak quotes would make very difficult to use.

There are, however, ways to use environment variables within an awk script.

You can declare your own variable:

read peak
awk -vpeak="$peak" '$0 ~ /peak/ { c=3 } c&&c--' consolelog.log > testing.txt

Or you can just tell awk to look at the one you just used read to fill:

read peak
awk '$0 ~ /ENVIRON["peak"]/ { c=3 } c&&c--' consolelog.log > testing.txt

Your code:

echo "Enter peak value"
read peak
awk '/${peak}/{c=3}c&&c--' consolelog.log > testing.txt

This does not work because strong quotes prevent the shell from performing variable expansion. This is good because awk uses a lot of syntax that weak quotes would make very difficult to use.

There are, however, ways to use environment variables within an awk script.

You can declare your own variable:

read peak
awk -vpeak="$peak" '$0 ~ peak { c=3 } c&&c--' consolelog.log > testing.txt

Or you can just tell awk to look at the one you just used read to fill:

read peak
awk '$0 ~ ENVIRON["peak"] { c=3 } c&&c--' consolelog.log > testing.txt
added 82 characters in body
Source Link
DopeGhoti
  • 79.3k
  • 10
  • 107
  • 141

Your code:

echo "Enter peak value"
read peak
awk '/${peak}/{c=3}c&&c--' consolelog.log > testing.txt

This does not work because strong quotes prevent the shell from performing variable expansion. This is good because awk uses a lot of syntax that weak quotes would make very difficult to use.

There are, however, ways to use environment variables within an awk script.

You can declare your own variable:

read peak
awk -vpeak="$peak" '$0 ~ /peak/ { stuffc=3 } c&&c--' consolelog.log > testing.txt

Or you can just tell awk to look at the one you just used read to fill:

read peak
awk '$0 ~ /ENVIRON["peak"]/ { stuffc=3 } c&&c--' consolelog.log > testing.txt
echo "Enter peak value"
read peak
awk '/${peak}/{c=3}c&&c--' consolelog.log > testing.txt

This does not work because strong quotes prevent the shell from performing variable expansion. This is good because awk uses a lot of syntax that weak quotes would make very difficult to use.

There are, however, ways to use environment variables within an awk script.

You can declare your own variable:

read peak
awk -vpeak="$peak" '$0 ~ /peak/ { stuff }'

Or you can just tell awk to look at the one you just used read to fill:

read peak
awk '$0 ~ /ENVIRON["peak"]/ { stuff }'

Your code:

echo "Enter peak value"
read peak
awk '/${peak}/{c=3}c&&c--' consolelog.log > testing.txt

This does not work because strong quotes prevent the shell from performing variable expansion. This is good because awk uses a lot of syntax that weak quotes would make very difficult to use.

There are, however, ways to use environment variables within an awk script.

You can declare your own variable:

read peak
awk -vpeak="$peak" '$0 ~ /peak/ { c=3 } c&&c--' consolelog.log > testing.txt

Or you can just tell awk to look at the one you just used read to fill:

read peak
awk '$0 ~ /ENVIRON["peak"]/ { c=3 } c&&c--' consolelog.log > testing.txt
Source Link
DopeGhoti
  • 79.3k
  • 10
  • 107
  • 141
Loading