Sample Header Ad - 728x90

Replace a string in a script without modifying the file, and then to execute it

1 vote
2 answers
593 views
I have both BSD (default) and GNU Awk implementations installed on a Mac (the latter is envoked using gawk instead of just awk), and I have a shell script with contents like this:
none
awk -v maxLen=72 '
    .
    .
    .
' "$1" > "$2"
Now the tricky part. To work correctly, the script must use GNU Awk. Which means I have at least two options: 1)To modify the first line of the script so that there will be gawk instead of awk, 2) To make a system-wide alias for GNU Awk so that it will be envoked using awk instead gawk. But I would prefer to avoid either option, and instead to execute the script using a wrapper. That is, instead of
none
./script.sh input.txt output.txt
I would prefer something like
none
sed -e 's/awk/gawk/' script.sh
and then to pass the output to Zsh somehow. I was told this is possible using Zsh process substitution feature, but how?
Asked by jsx97 (1347 rep)
Sep 2, 2024, 07:26 PM
Last activity: Sep 3, 2024, 05:58 AM