[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Sed & Awk



On Fri, Aug 31, 2001 at 09:27:19AM -0700, Dan Souza wrote:
> Sorry, I dont know if this is the right group, but here goes anyway.

debian-user@lists.debian.org would have been correct.

> I have a text file containing a document (eg this posting) which is
> formatted as such.  I need to import this into a database, and so I
> need to format the text to do this.
> I want the text to be 'cut' every 300 or so characters, and then
> create a flat file from this, with line numbers.
> eg.  
> "1","blah blah bla"   # (300 characters of blah)
> "2","h blah blah b"   # (and again)
> 
> I need to get rid of the carriage returns, and it would be preferable
> to get rid of the too much whitespace.

Escapes me why you'd want it formatted that way (if your DBMS doesn't
support strings of arbitrary length, or blobs, get a new DBMS!), but
here goes... :-)

tr -s '[:space:]' ' ' <file | fold -w 300

Cheers,

  Richard

-- 
  __   _
  |_) /|  Richard Atterer     |  CS student at the Technische  |  GnuPG key:
  | \/¯|  http://atterer.net  |  Universität München, Germany  |  0x888354F7
  ¯ ´` ¯

Attachment: pgprFhLp3xLCm.pgp
Description: PGP signature


Reply to: