Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 9 Sep 2017 11:14:02 -0500
From:      edgar <edgar@pettijohn-web.com>
To:        Ernie Luzar <luzar722@gmail.com>, Yuri Pankov <yuripv@gmx.com>
Cc:        Polytropon <freebsd@edvax.de>,  "=?utf-8?Q?freebsd-questions=40freebsd.org?=" <freebsd-questions@freebsd.org>
Subject:   Re: Re: script code for end-line
Message-ID:  <2b79276f-aa2a-47d1-810a-4594bda0beb1@localhost>
In-Reply-To: <59B4087B.2070005@gmail.com> <c8715d2d-cb1f-592b-7541-a556fa5645a7@gmx.com>
References:  <59B332A3.1000205@gmail.com> <20170909030257.d2718c00.freebsd@edvax.de> <c8715d2d-cb1f-592b-7541-a556fa5645a7@gmx.com>

next in thread | previous in thread | raw e-mail | index | archive | help
 
 
I think some example input may be helpful. It sounds like dos2unix may be useful. However, sed should be able to help as well.
 
 Either way without knowing exactly what the input may be and exactly what you want to accomplish it's hard to say.
 
 

 
 
 
 
 
>  
> On Sep 9, 2017 at 10:27 AM,  <Ernie Luzar>  wrote:
>  
>  
>  Yuri Pankov wrote:  >  On Sat, 9 Sep 2017 03:02:57 +0200, Polytropon wrote:  >>  On Fri, 08 Sep 2017 20:15:31 -0400, Ernie Luzar wrote:  >>>   >>>  I have a file that has blank lines with ^M in position one.  >>>   >>>  I have this if [ "$end-line" = "^M"]; then  >>>   >>>   >>>  Is that the correct way to code that between the quotes?  >>   >>  That will only match the literal string ^M (^ and M).  >>  String evaluation and comparison at this low level  >>  isn't a native skill of sh. There is a way of encoding  >>  characters as octal values, such as \015 for \r, which  >>  equals ^M and 0x0D, but /bin/test (which is [) can only  >>  compare strings.  >>   >>  Here is a terrible workaround (not tested):  >>   >>  if [ `echo ${end-line} | od -x | head -n 1 | awk '{ print $2 }'` =  >>  "000d" ]; then  >>  ... do something ...  >>  fi  >>   >>  Check if there is already a tool for what you're trying  >>  to accomplish (e. g., tr, sed, recode, iconv). ;-)  >   >  Actually, you can i
nsert real ^M characters and /bin/test should be able  >  to handle them - press ctrl+V ctrl+M.  >  .  >  I read the man page on the test command and did not come away with the syntax to use in a script. An example showing usage inside of the "if" statement sure would be more helpful to understand how it works. Thanks _______________________________________________ freebsd-questions@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org" 
>  
     
From owner-freebsd-questions@freebsd.org  Sat Sep  9 16:33:26 2017
Return-Path: <owner-freebsd-questions@freebsd.org>
Delivered-To: freebsd-questions@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id F343EE20107
 for <freebsd-questions@mailman.ysv.freebsd.org>;
 Sat,  9 Sep 2017 16:33:26 +0000 (UTC)
 (envelope-from freebsd@edvax.de)
Received: from mailrelay10.qsc.de (mailrelay10.qsc.de [212.99.163.152])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client CN "*.antispameurope.com",
 Issuer "TeleSec ServerPass DE-2" (verified OK))
 by mx1.freebsd.org (Postfix) with ESMTPS id 641C16EFD1
 for <freebsd-questions@freebsd.org>; Sat,  9 Sep 2017 16:33:25 +0000 (UTC)
 (envelope-from freebsd@edvax.de)
Received: from mx01.qsc.de ([213.148.129.14]) by mailrelay10.qsc.de;
 Sat, 09 Sep 2017 18:33:22 +0200
Received: from r56.edvax.de (port-92-195-85-107.dynamic.qsc.de [92.195.85.107])
 (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
 (No client certificate requested)
 by mx01.qsc.de (Postfix) with ESMTPS id 42C4E3CBF9;
 Sat,  9 Sep 2017 18:33:21 +0200 (CEST)
Received: from r56.edvax.de (localhost [127.0.0.1])
 by r56.edvax.de (8.14.5/8.14.5) with SMTP id v89GXKDJ003014;
 Sat, 9 Sep 2017 18:33:20 +0200 (CEST)
 (envelope-from freebsd@edvax.de)
Date: Sat, 9 Sep 2017 18:33:20 +0200
From: Polytropon <freebsd@edvax.de>
To: edgar <edgar@pettijohn-web.com>
Cc: Ernie Luzar <luzar722@gmail.com>, Yuri Pankov <yuripv@gmx.com>,
 Polytropon <freebsd@edvax.de>, "freebsd-questions@freebsd.org"
 <freebsd-questions@freebsd.org>
Subject: Re: script code for end-line
Message-Id: <20170909183320.7899bcc0.freebsd@edvax.de>
In-Reply-To: <2b79276f-aa2a-47d1-810a-4594bda0beb1@localhost>
References: <59B332A3.1000205@gmail.com>
 <20170909030257.d2718c00.freebsd@edvax.de>
 <c8715d2d-cb1f-592b-7541-a556fa5645a7@gmx.com>
 <2b79276f-aa2a-47d1-810a-4594bda0beb1@localhost>
Reply-To: Polytropon <freebsd@edvax.de>
Organization: EDVAX
X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2)
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
X-cloud-security-sender: freebsd@edvax.de
X-cloud-security-recipient: freebsd-questions@freebsd.org
X-cloud-security-Virusscan: CLEAN
X-cloud-security-disclaimer: This E-Mail was scanned by E-Mailservice on
 mailrelay10.qsc.de with A292768343B
X-cloud-security-connect: mx01.qsc.de[213.148.129.14], TLS=1, IP=213.148.129.14
X-cloud-security: scantime:.1285
X-BeenThere: freebsd-questions@freebsd.org
X-Mailman-Version: 2.1.23
Precedence: list
List-Id: User questions <freebsd-questions.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/freebsd-questions>, 
 <mailto:freebsd-questions-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-questions/>;
List-Post: <mailto:freebsd-questions@freebsd.org>
List-Help: <mailto:freebsd-questions-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/freebsd-questions>, 
 <mailto:freebsd-questions-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Sat, 09 Sep 2017 16:33:27 -0000

On Sat, 9 Sep 2017 11:14:02 -0500, edgar wrote:
> I think some example input may be helpful. It sounds like dos2unix
> may be useful. However, sed should be able to help as well.

Yes. In case "search & replace" is a way to go, tools like recode,
iconv, sed or tr are a comfortable way to deal with ^Ms.



>  Either way without knowing exactly what the input may be and exactly
> what you want to accomplish it's hard to say.

It's also important to verify the variable contents at each stage,
compared with the input format, for example, if the lines in question
only contain ^M, that is \r, or \r\n (MS-DOS and "Windows" 2-byte
line break); od -x is a convenient tool to find out.

I have verified the following test to work for the "single byte
scenario":

	if [ `echo -n ${end_line} | od -x | head -n 1 | awk '{ print $2 }'` = "000d" ]; then
		echo "CR"
	else
		echo "no CR"
	fi

It's working in a Rube-Goldberg manner. ;-)


-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?2b79276f-aa2a-47d1-810a-4594bda0beb1>