bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gensub embeds spurious carriage return in dos-format input


From: michael humphrey
Subject: gensub embeds spurious carriage return in dos-format input
Date: Thu, 2 Dec 2004 20:04:45 -0000

the problem occurs when the input file is dos-format and disappears when the 
input file is in unix-format.

the problem concerns regular expression component specifiers.
namely, a spurious carriage return ("\r") is embedded at the end of the 
replaced text called out by a component specifier.
note that the called out text is from the middle of the input line, so the 
input line itself can not be the source of the problem.

the console session below demonstrates the problem.
the configuration is: intel i586/Windows 2000Pro, cygwin 1.5.5







[console session]

address@hidden /nth/wsr
$ gawk -W version
GNU Awk 3.1.3
Copyright (C) 1989, 1991-2003 Free Software Foundation.

address@hidden /nth/wsr
$ cygcheck -sr
Cygwin Win95/NT Configuration Diagnostics
Current System Time: Thu Dec 02 18:47:21 2004
...
    Cygwin DLL version info:
        DLL version: 1.5.5
        DLL epoch: 19
        DLL bad signal mask: 19005
        DLL old termios: 5
        DLL malloc env: 28
        API major: 0
        API minor: 94
        Shared data: 3
        DLL identifier: cygwin1
...

address@hidden /nth/wsr
$ cat gawk-problem.awk 
/<!-- http.* -->/ {
# gensub embeds "\r" in result if input is dos-format
  lurl = gensub(/<!-- (http.*) -->/, "\\1", 1, $0)
printf "KKA lurl=[%s]\n", lurl 
# strip trailing "\r" from previous result
  nlurl = gensub(/[\n\r]*$/, "", 1, lurl)
printf "KKA nlurl=[%s]\n", nlurl 
  }

{
  next
  }

address@hidden /nth/wsr
$ cat dos-input.txt
<!-- http://mmm.vv.nu/ee/yy -->
<p> kkkkkkkkkkkkkk  <p> lllllllllllllll  

address@hidden /nth/wsr
$ gawk -f gawk-problem.awk < dos-input.txt
]KA lurl=[http://mmm.vv.nu/ee/yy
KKA nlurl=[http://mmm.vv.nu/ee/yy]

address@hidden /nth/wsr
$ cat dos-input.txt | dos2unix > unix-input.txt

address@hidden /nth/wsr
$ gawk -f gawk-problem.awk < unix-input.txt
KKA lurl=[http://mmm.vv.nu/ee/yy]
KKA nlurl=[http://mmm.vv.nu/ee/yy]


reply via email to

[Prev in Thread] Current Thread [Next in Thread]