|
Prev: fixed-size records
Next: awk command
From: steve.chambers on 17 Mar 2006 09:33 I'm stuck! Need to do a text replace in files to convert them from DOS into equivalent UNIX format (i.e. get rid of all the ^M characters). But am using a system that has a BusyBox UNIX implementation on it that supports a very limited set of unix commands. These are: alias break builtin cd chdir continue eval exec exit export false fc hash help jobs let local pwd read readonly return set setvar shift times trap true type ulimit umask unalias unset wait [ ash basename busybox cat chmod cp cut df dmesg du echo env false find free freeramdisk halt hostid hostname init kill killall ln logger ls mkdir mknod mktemp more mount mv nc nslookup ps pwd reboot rm rmdir sh sleep sync test tftp touch traceroute true umount uname uniq uptime Can anyone see a way to do it from the command line automatically with these commands? I'm aware that I could do it in Vi (which is also available but not listed) but need it to be done at the command line automatically as part of a script rather than as a manual process. Just in case anyone suggests it, the system doesn't have any implementation of SED, EMACS or TR. Any advice on this would be much appreciated! Cheers, Steve
From: Eric Moors on 17 Mar 2006 09:43 steve.chambers(a)gmail.com wrote: > I'm stuck! Need to do a text replace in files to convert them from DOS > into equivalent UNIX format (i.e. get rid of all the ^M characters). > But am using a system that has a BusyBox UNIX implementation on it that > supports a very limited set of unix commands. These are: > > alias break builtin cd chdir continue eval exec exit export > false fc hash help jobs let local pwd read readonly return set > setvar shift times trap true type ulimit umask unalias unset > wait [ ash basename busybox cat chmod cp cut df dmesg du echo > env false find free freeramdisk halt hostid hostname init kill > killall ln logger ls mkdir mknod mktemp more mount mv nc nslookup > ps pwd reboot rm rmdir sh sleep sync test tftp touch traceroute > true umount uname uniq uptime > > Can anyone see a way to do it from the command line automatically with > these commands? I'm aware that I could do it in Vi (which is also > available but not listed) but need it to be done at the command line > automatically as part of a script rather than as a manual process. Just > in case anyone suggests it, the system doesn't have any implementation > of SED, EMACS or TR. > > Any advice on this would be much appreciated! > As you appear to have cut available, you could try this: cut -d ^M -f1 inputFile > outputfile Eric
From: steve.chambers on 17 Mar 2006 11:03 Hmmm, good suggestion. It may *possibly* work but unfortunately I'm not quite there with it yet. Tried the line as suggested and it gave the message of "cut: the delimiter must be a single character". So I then tried using \r instead of ^M and it simply removed all the ends of lines with r in them from the r onwards. I then played about a bit and discovered that if I do a range (e.g. -f1-5) then it includes the delimiters in the output (in this case the 'r' character) but if I do a single field e.g. f1, f2 etc. it doesn't. So not sure if it will be workable as to convert into UNIX format we need to remove the \r but keep the \n from \r\n. Aaarrgh, frustrating! So in summary I guess there's two new questions here I don't know the answer to:- 1. How do I specify the carriage return character? (have tried ^M, \r, "^M", "\r", \\r, "\\r" but none of these work) 2. Would there be any way of using cut to not include the delimiters in order to preserve the \n? Not looking too hopeful... Oh, one other thing, I found where the other commands that are available are in /usr/bin folder. They are: [ erase killall nc uniq basename eraseall lock nftl_format unlock cut fcp logger nftldump uptime doc_loadbios free mkfs.jffs nslookup vi du ftl_check mtd_debug passwd einfo ftl_format nanddump test elvis grep nandtest tftp env hostid nandwrite traceroute Probably not much help for solving this but hopefully someone might disagree...?
From: Stephane Chazelas on 17 Mar 2006 11:24 On 17 Mar 2006 08:03:01 -0800, steve.chambers(a)gmail.com wrote: > Hmmm, good suggestion. It may *possibly* work but unfortunately I'm not > quite there with it yet. Tried the line as suggested and it gave the > message of "cut: the delimiter must be a single character". [...] The suggestion was: cut -d^M -f1 where ^M was the CR character, not the two character ^ and M. To type that character at the prompt, type <Ctrl-V> followed by <Ctrl-M> (or <Return>). Alternatively, you should be able to do either: CR=`printf '\r'` or CR=`echo '\r'` or CR=`echo -e '\r'` cut -d "$CR" -f1 -- Stephane
From: Chris F.A. Johnson on 17 Mar 2006 11:25
On 2006-03-17, steve.chambers(a)gmail.com wrote: > Hmmm, good suggestion. What is? Please quote context. > It may *possibly* work but unfortunately I'm not > quite there with it yet. Tried the line as suggested and it gave the > message of "cut: the delimiter must be a single character". So I then > tried using \r instead of ^M and it simply removed all the ends of > lines with r in them from the r onwards. I then played about a bit and > discovered that if I do a range (e.g. -f1-5) then it includes the > delimiters in the output (in this case the 'r' character) but if I do a > single field e.g. f1, f2 etc. it doesn't. So not sure if it will be > workable as to convert into UNIX format we need to remove the \r but > keep the \n from \r\n. Aaarrgh, frustrating! > > So in summary I guess there's two new questions here I don't know the > answer to:- > > 1. How do I specify the carriage return character? (have tried ^M, \r, > "^M", "\r", \\r, "\\r" but none of these work) Press control-V then control-M > 2. Would there be any way of using cut to not include the delimiters in > order to preserve the \n? cut -d '^M' -f1 FILE -- When answering to a Usenet post through Google groups, please click on "show options" at the top of the article, then click on the "Reply" in the article headers. (see <http://cfaj.freeshell.org/google>), ------ Chris F.A. Johnson, <http://cfaj.freeshell.org> ------ |