This is a small portion of a huge script. I am trying to extract particular lines from a file and append it to another file. I tried the following command in the shell.
cat "temp.xml" | awk 'NR >= 1 && NR <= 100' >> output
This works fine. But when I did this inside a shell script, it shows an error with awk.
The script is,
#!/bin/bash
line_start=1
line_end=100
content=$((cat "$1" | awk 'NR >= $line_start && NR <= $line_end'))
echo $content >> output
and the error is,
dev-005~# ./copy.sh temp.xml
./copy.sh: line 4: cat "temp.xml" | awk 'NR >= 1 && NR <= 100': syntax error: invalid arithmetic operator (error token is ""temp.xml" | awk 'NR >= 1 && NR <= 100'")
I don't understand what's causing the error.