Command awk under CYGWIN

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Command awk under CYGWIN
# 1  
Old 02-14-2017
Command awk under CYGWIN

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:

Code:
#!/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}"

This is the command not executed correctly

Code:
awk '/$line/,/<!--begin_channel-->/ " $1 | grep -v "$line" | grep -v "^<' > xxx

Thank you in advice if someone can help me.
# 2  
Old 02-14-2017
I don't quite follow/understand what you're trying to do and this is way too verbose, but...
Code:
awk "/$line/,/<!--begin_channel-->/" $1 | grep -v "$line" | grep -v '^<' > xxx

This User Gave Thanks to vgersh99 For This Post:
# 3  
Old 02-14-2017
No, is still not working Smilie

I have one input file like this: channels.xml
Code:
<!--begin_channel-->
Rai_1.png
<!--end_channel-->
1:0:1:EDF:16A:0:8D68:0:0:0:.png
Rai_1_+2HD.png
Rai_1_+1HD.png
.
.
.

This script need give me back one file like this: channels.sh

Code:
cp /cygdrive/c/ProgramData/data/picons/Rai_1.png /cygdrive/c/ProgramData/data/picons/duplicati/1_0_1_EDF_16A_0_8D68_0_0_0_.png
cp /cygdrive/c/ProgramData/data/picons/Rai_1.png /cygdrive/c/ProgramData/data/picons/duplicati/Rai_1_+2HD.png
cp /cygdrive/c/ProgramData/data/picons/Rai_1.png /cygdrive/c/ProgramData/data/picons/duplicati/Rai_1_+1HD.png
.
.

The command to use it is like:
Code:
{ bash }  »./script.sh channels.xml channels.sh /cygdrive/c/ProgramData/data/picons/ /cygdrive/c/ProgramData/data/picons/duplicati/

/cygdrive/c/ProgramData/data/picons/ is the source of the files
/cygdrive/c/ProgramData/data/picons/duplicati/ is the destination of the files

I hope is more clear Smilie

Last edited by Tapiocapioca; 02-14-2017 at 04:47 PM..
# 4  
Old 02-14-2017
would something like this be helpful?
awk -f tapi..awk channels.xml where tapi.awk is:
Code:
BEGIN {
  srcD="/cygdrive/c/ProgramData/data/picons"
  dstD="/cygdrive/c/ProgramData/data/picons/duplicati"
}
/<!--begin_channel-->/ {srcT=1; next}
/<!--end_channel-->/ {srcT=0; next}
srcT {srcF=$0;next}
srcF {
   gsub(":","_",$1)
   print "cp " srcD "/" srcF " " dstD "/" $1
}

you can work on this code to make it more flexible integrating with the shell of your choice!

Last edited by vgersh99; 02-14-2017 at 05:33 PM..
These 2 Users Gave Thanks to vgersh99 For This Post:
# 5  
Old 02-15-2017
Maybe I was wrong to explain, the script is working under Ubuntu but not under CYGWIN.
# 6  
Old 02-15-2017
Your cygwin's bash and awk versions probably differ from Ubuntu's. The exact output including error messages would seriously help us help you!

Last edited by RudiC; 02-15-2017 at 07:44 AM..
This User Gave Thanks to RudiC For This Post:
# 7  
Old 02-15-2017
Quote:
Originally Posted by Tapiocapioca
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:

Code:
#!/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}"

This is the command not executed correctly

Code:
awk '/$line/,/<!--begin_channel-->/ " $1 | grep -v "$line" | grep -v "^<' > xxx

Thank you in advice if someone can help me.
Quote:
Originally Posted by Tapiocapioca
Maybe I was wrong to explain, the script is working under Ubuntu but not under CYGWIN.
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:
Code:
awk -v Line="$line" '$0 ~ Line,/<!--begin_channel-->/' "$1" | grep -v "$line" | grep -v "^<" > xxx

or (using one process instead of 3):
Code:
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:
Code:
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???
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Experimental awk audio converter for CygWin and AudioScope.sh

Development machine:- Standard MBP 13 inch, OSX 10.7.5... GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin11) Copyright (C) 2007 Free Software Foundation, Inc. Scenario:- Audio capture for AudioScope.sh for CygWin without ANY third party installs. I am trying my hardest to get a... (6 Replies)
Discussion started by: wisecracker
6 Replies

2. Shell Programming and Scripting

script under cygwin suddenly says command not found

Running bash in cygwin under 2003 Server. I run about 6 shell windows. Every now and then when I check the machine, all of the scripts are scrolling and returning /usr/bin/whatever: command not found. I checked the event log for a windows event that would cause it, but there was nothing. I... (9 Replies)
Discussion started by: gman804s
9 Replies

3. Shell Programming and Scripting

bash command in makefile (cygwin)

Hello, In my make file (make 3.81), I use a combination of shell commands to automatically create the name of my build directory. OS := $(shell uname -s) ARCH := $(shell uname -m) KERN := $(shell uname -r | cut -d. -f 1,2) BDIR := $(OS)_$(KERN).$(ARCH)When I boot into different OSs, I... (7 Replies)
Discussion started by: LMHmedchem
7 Replies

4. UNIX for Dummies Questions & Answers

How to execute a command in Cygwin?

Hi, I have installed CYGWIN software in my system, can anyone suggest me how to run cat command in this software ? when i attempt to execute this command- $ cat /cygdrive/c/Program\Files/hello.txt. Result: No such file or directory. Please let me know how to execute. Regards, Kiran. (1 Reply)
Discussion started by: Kiran S
1 Replies

5. UNIX for Dummies Questions & Answers

Cygwin bash script and read command

Hello everyone, I am struggling a bit with a batch script that I need to run in cygwin. I work in winXP and I had to write some awk scripts to do some file manipulation, and now I would like to automate the process by just running a batch file so that my colleagues can use it easily. Now, the... (2 Replies)
Discussion started by: Teroc
2 Replies

6. Windows & DOS: Issues & Discussions

Fixing Cygwin Command Line

How do I change my command line to the standard appearance? (i.e.: The pwd is listed in green above the actual command line). Mine looks like http://sites.google.com/site/flcl178/Cygwin_Window_1.png and I want it to look like this http://sites.google.com/site/flcl178/cygwinLinkSetup.gif ... (2 Replies)
Discussion started by: LanguidLegend
2 Replies

7. Windows & DOS: Issues & Discussions

Output of ls command on Cygwin

what does the '+' sign stand for on the output of ls command on cygwin? -rw-------+ 1 milhan None 146783 Jun 19 12:10 schedule.pdf -rw-------+ 1 milhan None 320 Aug 15 17:14 current.txt -rw------- 1 milhan None 24576 Dec 28 2008 fdfd.txt (2 Replies)
Discussion started by: milhan
2 Replies

8. Shell Programming and Scripting

cygwin and remote find command problem

Sir, I want to get all the files in directory on a remote server which are dated newer than a specified file. I have ssh running and the command I am using is : for file_name in `ssh userid@IP find "/cygdrive/d/oracle/oradata/db/archive" -newer "1_44.DBF" -name '*.DBF' -type f -print | xargs -r... (2 Replies)
Discussion started by: nakod1
2 Replies

9. UNIX for Dummies Questions & Answers

How to use route command on SuSE & Cygwin

If I'm at a wireless cafe running SuSE and I want to read my mail but the wireless cafe blocks port 25 for smtp but I have a VPN connection to my home machine, how do I use the "route" command. If I'm at home on my windows machine and have a VPN connection to another network, can I use the... (3 Replies)
Discussion started by: siegfried
3 Replies

10. UNIX for Dummies Questions & Answers

Sed command in cygwin

I am new to unix and lerning tru cygwin (unix simulation on windows) i am trying to lern sed command and want to interchange first and second no in a string. What i mean is i want gauri 1234 556 to gauri 556 1234 i am getting the following error $ echo gauri 1234 556 | sed s/\(*\)... (2 Replies)
Discussion started by: gauri_agr
2 Replies
Login or Register to Ask a Question