From: Ertugrul Soeylemez on 25 Jun 2006 03:36 floyd(a)apaflo.com (Floyd L. Davidson) (06-06-24 09:04:21): > >Finally someone with the reasonable answer. If he's working from a > >text file with "^M" imbedded, he could A) vi the file and perform a > >global search and replace, or B) pipe the output to sed using > >'/s[CTRL][v][CTRL][M]//g' to remove the "^M" before using the useradd > >command. > > That is exactly what /col/ was designed to do. Pipe the file > through /col/, using -x and perhaps -b options. Even easier: tr -d "\r" < SRCFILE > DESTFILE Regards.
From: Floyd L. Davidson on 25 Jun 2006 05:53 Ertugrul Soeylemez <never(a)drwxr-xr-x.org> wrote: >floyd(a)apaflo.com (Floyd L. Davidson) (06-06-24 09:04:21): > >> >Finally someone with the reasonable answer. If he's working from a >> >text file with "^M" imbedded, he could A) vi the file and perform a >> >global search and replace, or B) pipe the output to sed using >> >'/s[CTRL][v][CTRL][M]//g' to remove the "^M" before using the useradd >> >command. >> >> That is exactly what /col/ was designed to do. Pipe the file >> through /col/, using -x and perhaps -b options. > >Even easier: > > tr -d "\r" < SRCFILE > DESTFILE col -xb < SRCFILE > DESTFILE Hmmm... that looks to be 3 characters shorter! :-) I don't /tr/ as being easier, plus it is not as functional. /tr/ only translates exactly what you tell it to, while /col/ was specifically designed to remove unknown control sequences. For example, with the -b option it removes all but that last of any series of "<BS>c", where c is any character, and with -x it will replace tabs with spaces. There is no way to get /tr/ to do those too, plus remove any other non-effective carriage control sequences. -- Floyd L. Davidson <http://www.apaflo.com/floyd_davidson> Ukpeagvik (Barrow, Alaska) floyd(a)apaflo.com
From: Ertugrul Soeylemez on 25 Jun 2006 06:48
floyd(a)apaflo.com (Floyd L. Davidson) (06-06-25 01:53:33): > > Even easier: > > > > tr -d "\r" < SRCFILE > DESTFILE > > col -xb < SRCFILE > DESTFILE > > Hmmm... that looks to be 3 characters shorter! :-) > > I don't /tr/ as being easier, plus it is not as functional. > > /tr/ only translates exactly what you tell it to, while /col/ was > specifically designed to remove unknown control sequences. For > example, with the -b option it removes all but that last of any series > of "<BS>c", where c is any character, and with -x it will replace tabs > with spaces. There is no way to get /tr/ to do those too, plus remove > any other non-effective carriage control sequences. Well, 'col' is more intelligent than 'tr', and processes its input. In some situations, you don't want that, and instead just remove (or translate) a selected set of characters. 'tr' is better in that case. Regards, E.S. |