[SGVLUG] Shell fun: cutting the last field of a record...
Emerson, Tom
Tom.Emerson at wbconsultant.com
Fri Mar 24 12:15:04 PST 2006
I've got a file delimited with vertical-bar characters (|)
The last field of each record is a filename, and there is no trailing
"|" in the record.
I've got a process that is extracting the name as follows:
for REC in `cat worklist`
do
fname=`echo $REC | cut -f6 -d"|"`
<does something thaqt creates the file "$fname">
done
Say for instance the file "worklist" looks like this:
rec1|field2|field3|field4|field5|filea
rec2|field2|field3|field4|field5|fileb
rec3|field2|field3|field4|field5|filec^M (file has an embedded
carraige return at the end)
When I'm done, a listing of the directory with "-b" (show embedded
specials as \octal) shows that the carraige return ended up as part of
the filename:
filea
fileb
filec\015
how can I eliminate that trailing "/r" ? (and before you ask, the
workfile is being generated by a database extract of fields that were
populated by a [visual] spreadsheet-style database query tool, so
inadvertantly pressing <enter> during data entry could easily go
unnoticed)
More information about the SGVLUG
mailing list