script code for end-line

edgar edgar at pettijohn-web.com
Sat Sep 9 16:20:47 UTC 2017


 
 
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 at freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org" 
>  
     


More information about the freebsd-questions mailing list