Differences with gawk on cmd vs cygwin


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Differences with gawk on cmd vs cygwin
# 1  
Old 11-09-2018
Differences with gawk on cmd vs cygwin

I have this script (thanks Don!) that runs as expected in cygwin:
Code:
gawk -F, 'NR == 1{print "Source,Well_Source,Volume,Destination_Well,Destination"; OFS = ","; next}/Ladder/{next}LAST2 && $2 != LAST2{print "PCR_Plate", ++CNT, (SUM > 10)?800/SUM:0, 1, "Deadpool"; SUM = 0}{SUM += ( $4 > 430 && $4 < 490 && $5 > 45 ) ? $5 : 0; LAST2  = $2}' Process1.txt

However, when I run it on cmd:
Code:
C:\cygwin64\bin\gawk -F, 'NR == 1{print "Source,Well_Source,Volume,Destination_Well,Destination"; OFS = ","; next}/Ladder/{next}LAST2 && $2 != LAST2{print "PCR_Plate", ++CNT, (SUM > 10)?800/SUM:0, 1, "Deadpool"; SUM = 0}{SUM += ( $4 > 430 && $4 < 490 && $5 > 45 ) ? $5 : 0; LAST2  = $2}' Process1.txt

It just goes idle. The first part prints fine:
Code:
C:\cygwin64\bin\gawk -F, 'NR == 1{print "Source,Well_Source,Volume,Destination_Well,Destination"; OFS = ","; next}' Process1.txt

I have tried a bunch of different things to make it work with no luck. Any help will be greatly appreciated!
PS. I am attaching the infile (Process1.txt)

Last edited by Xterra; 11-09-2018 at 09:40 PM..
# 2  
Old 11-10-2018
This is probably a quoting issue, which works differently in Windows. Try putting the script itself in a script file :

Code:
BEGIN { 
  FS="," 
} 

NR == 1 {
  print "Source,Well_Source,Volume,Destination_Well,Destination"
  OFS = ","
  next
}

/Ladder/ {
  next
}

LAST2 && $2 != LAST2 {
  print "PCR_Plate", ++CNT, (SUM > 10)?800/SUM:0, 1, "Deadpool"; SUM = 0
}

{
  SUM += ( $4 > 430 && $4 < 490 && $5 > 45 ) ? $5 : 0
  LAST2  = $2
}

and call the command like this:
Code:
awk -f this_script Process1.txt

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 11-10-2018
That worked like a charm! Thanks a TON!
PS. Still, I am bit curious, would it be possible to fix the script in such way that can be run directly from the cmd terminal?
# 4  
Old 11-13-2018
I have no way to test it, since I have no Windows, but could you give this a try:
Code:
C:\cygwin64\bin\gawk -F, "NR == 1{print \"Source,Well_Source,Volume,Destination_Well,Destination\"; OFS = \",\"; next}/Ladder/{next}LAST2 && $2 != LAST2{print \"PCR_Plate\", ++CNT, (SUM > 10)?800/SUM:0, 1, \"Deadpool\"; SUM = 0}{SUM += ( $4 > 430 && $4 < 490 && $5 > 45 ) ? $5 : 0; LAST2  = $2}" Process1.txt




--
Otherwise try:
Code:
C:\cygwin64\bin\gawk -F, "NR == 1{print \"Source,Well_Source,Volume,Destination_Well,Destination\"; OFS = \",\"; next}/Ladder/{next}LAST2 && \$2 != LAST2{print \"PCR_Plate\", ++CNT, (SUM > 10)?800/SUM:0, 1, \"Deadpool\"; SUM = 0}{SUM += ( \$4 > 430 && \$4 < 490 && \$5 > 45 ) ? \$5 : 0; LAST2  = \$2}" Process1.txt

This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 11-14-2018
Quote:
Originally Posted by Xterra
That worked like a charm! Thanks a TON!
PS. Still, I am bit curious, would it be possible to fix the script in such way that can be run directly from the cmd terminal?
That is tricky. It probably is, but may be gawk.exe-dependent as much as cmd dependent. Quoting in CPM/DOS/Windows has traditionally been a free-for-all, with much implementation left up to whatever command you're using.
# 6  
Old 11-15-2018
Scrutinizer
Your first did the trick
Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. SCO

Need help with gawk

I am trying to use gawk to search a file and put the second value of the string into a string. gawk -F: '$1~/CXFR/ {print $2}' go.dat Below is the file 'go.dat' ==================== HOME :/ CTMP :/tmp CUTL :/u/rdiiulio/bin CWRK :/u/work CXFR :/u/xfer ... (1 Reply)
Discussion started by: trolley
1 Replies

2. Shell Programming and Scripting

Perl open(CMD, "cmd |"); buffering problem..

Hello, There's a third-party application's command that shows the application's status like "tail -f verybusy.log". When use the command, the output comes every 1-sec. but when it goes in a script below the output comes every 8-sec...What is the problem and how can I fix it? open(CMD,... (2 Replies)
Discussion started by: Shawn, Lee
2 Replies

3. Shell Programming and Scripting

opening new instance of cygwin from withing cygwin

I'm using cygwin on win7, What I would like to do is something like this: cygstart cygwin tail -f /foo/test.log | perl -pe 's/error/\e I know I can start a new instance using either of these: mintty -e ... cygstart tail ... But neither of those open in ANSI mode, so I can't do... (0 Replies)
Discussion started by: Validatorian
0 Replies

4. Shell Programming and Scripting

Unix cmd prompt how to get old cmd run?

Hi, I am using SunOS I want to serch my previous command from unix prompt (like on AIX we can search by ESC -k) how to get in SunOs urgent help require. (10 Replies)
Discussion started by: RahulJoshi
10 Replies

5. Shell Programming and Scripting

Differences between 2 Flat Files and process the differences

Hi Hope you are having a great weeknd !! I had a question and need your expertise for this : I have 2 files File1 & File2(of same structure) which I need to compare on some columns. I need to find the values which are there in File2 but not in File 1 and put the Differences in another file... (5 Replies)
Discussion started by: newbie_8398
5 Replies

6. Shell Programming and Scripting

Gawk Help

Hi, I am using the script to print the portion of the file containing a particular string. But it is giving error "For Reading (No such file or directory). I am using cygwin as unix simulator. cat TT35*.log | gawk -v search="12345678" ' /mSOriginating /,/disconnectingParty/ { ... (1 Reply)
Discussion started by: vanand420
1 Replies

7. UNIX for Advanced & Expert Users

Cygwin <--> CMD App Problem (Terminal Type?)

I'm not sure if this is the right place to post this, but here it is. We have a nightly process that runs on an HP-UX box to stop our application and backend database servers, unmount their SAN hosted file systems, and then snapshot the SAN LUNs for backup and refresh of data on "report" and... (1 Reply)
Discussion started by: deckard
1 Replies

8. Shell Programming and Scripting

gawk HELP

I have to compare records in two files. It can be done using gawk/awk but i am unable to do it. Please help me File1 ABAAAAAB BC asa sa ABAAABAA BC bsa sm ABBBBAAA BC bxz sa ABAAABAB BC csa sa ABAAAAAA BC dsa sm ABBBBAAB BC dxz sa File 2 ABAAAAAB BC aas ba ABAAAAAB BC asa sa... (6 Replies)
Discussion started by: sandeep_hi
6 Replies

9. UNIX for Dummies Questions & Answers

man <cmd> >> cmd.txt

I've noticed most of my postings here are because of syntax errors. So I want to begin compiling a large txt file that contains all the "man <cmd>" of the commands I most have problems with. I ran a "man nawk >> nawk.txt" but it included a header/footer on each "page". Anyone know how I'd be... (6 Replies)
Discussion started by: yongho
6 Replies
Login or Register to Ask a Question