AWK Variable instead inputfile

Hi ,

can I use var1 instead of inputfile (index.html) in AWK?

var1='<script>text1 asd asd asd</script> 
text2 asd, asd
text3 asd asd asd asd 
text4 asdasdasd asd asd'

awk  '/<script /{p=1} /<\/script>/{p=0; next}!p' index.html 

Thank you!

Yes you could. All you have to change here is like below.

 echo var1 | awk  '/<script /{p=1} /<\/script>/{p=0; next}!p' 

Cheers! :slight_smile:

I don't think this will work. What are you trying to achieve? What is your desired input and output?

You could do that:

echo "$var1"|awk  '/<script /{p=1} /<\/script>/{p=0; next}!p'

Ahhh.. C'mon I missed that $ again!! :frowning: :wall:

You missed the dollar sign and the double-quotes :). The quotes are important to preserve the new-lines.

Also it should probably be

awk  '/<script>/{p=1} /<\/script>/{p=0; next}!p'

or

awk  '/<script>/{p=1}!p; /<\/script>/{p=0}'

But we will only know for sure if we know the intended output..

THANK YOU GUYS!!! THAT IS WHAT I WANT :slight_smile: :slight_smile: :slight_smile: :slight_smile:

I was trying with

echo $result | awk '{gsub(/<[^>]+>/, "", $0);  print $0}'