One my friend wrote one script on his machine linux, when I try to use it under cygwin I recive one error about the command awk. Is there someone can suggest me the way to fix the error? The script is wrote using gawk and I have no idea what kind of comand is used by cygwin.
This is the script:
#!/bin/bash
#credits xxx
#per info email: xxx
#colori
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
if [ $# -ne 4 ]
then
echo -e "${RED}ERRORE${NC}, inserire $0 filein fileout pathlogo_from pathlogo_to"
echo -e "${RED}Ricorda${NC} le enstensioni!"
exit 0
fi
if [ -f $2 ]
then
echo -n -e "File $2 esistente, vuoi ${RED}sovrascrivere${NC}?(Y/n) "
read scelta
if [ $scelta != 'Y' ]
then
exit 0
else
rm $2
fi
fi
awk '/\<!--begin_channel--\>/{flag=1; next} /\<!--end_channel--\>/{flag=0} flag' $1 > temp
while read line
do
awk '/$line/,/<!--begin_channel-->/ " $1 | grep -v "$line" | grep -v "^<' > xxx
for channel in `cat xxx`
do
channel=`echo $channel | tr ")" "_" | tr "(" "_" | tr ":" "_"`
echo "cp $3/$line $4/$channel"
done
done <temp >> $2
rm temp
rm xxx
echo -e "${GREEN}File $2 creato correttamente${NC}"
No. No. No. No way! The command that you say is not executed correctly on CYGWYN cannot possibly work on any Linux or CYGWIN system.
As long as there are no slash ( / ) characters in the file named by the 1st command-line argument given to your script, the code vgersh99 suggested should work for you (as long as the note at the end of this post does not apply). If there could be one or more slash characters in that file, try replacing that line with:
awk -v Line="$line" '
/<!--begin_channel-->/ { p = 0 }
p && ! /^</
$0 ~ Line { p = 1 }' "$1" > xxx
Note, however, that none of these suggestions will work if the text in the file named by the 1st command-line argument to your script contains characters that are "special" in an extended or basic regular expression if the intent is to match them as literal characters.
But, of course, now that I see post #3, it is obvious that absolutely no chance that this script is going to produce any output at all similar to the output you say you want. With the sample input you have shown us, the output from the 1st awk command in your script will produce the output:
Rai_1.png
in the file named temp and the 1st grep in the 2nd awk pipeline will discard that output. There is nothing in your code that makes any attempt to create cp commands as output.
It is also interesting to note that your script requires four command-line arguments, but only the 1st two are used???
I tried to follow the suggestions but I still can't run it I am really bad about. If someone want also suggest a different solution is ok. What I need is one file like I published before and the oportunity to replace the character : with _ and the | with _