Here's an awk for ya:

#!/bin/sh
cat pipes.txt | awk '
BEGIN{
  # Set Field Separator
  FS="|"
}
{
  # Start for loop from 1 to number of fields.
  for(x=1 ; x<=NF ; x++){
    #
    # Print "FIELD" Have to \" Escape the printable quotes.
    #
    printf "\"%s\"",$x
    #
    # If x is less than Number of Fields, print a comma.
    #
    if(x < NF){ 
      printf ","
    }
  }
    # Finish line of with a CR. (newline)
    printf "\n"
}'
# end script

Here is the source file "pipes.txt" :

Gary|Gary|Address|City|State
George|George|Somewhere|Big City|Small State
Steve|Steve|Nowhere|Small City|Big State
Steve|George|Gary|Address|Somewhere|Nowhere|City|State

Be aware, If a line ends in a "|", this script will print "field",""
Left that fun for the user ;-)

Have fun,
--
Rick L. Mantooth
[EMAIL PROTECTED]
"Auntie Em: Hate you, Hate Kansas, taking the dog." -Dorothy

On Sun, 21 Nov 1999, gnielson wrote:

> Hi everyone:
> 
> Would anyone mind sharing a script if they have one on converting pipe
> delimited ascii data files to comma delimited as in:
> 
> from Gary|Gary|Address|City|State
> to   "Gary","Gary","Address","City","State"
> 
> I could use a simple perl command to change every pipe to "," but that
> does not take care of the beginning and ending of each line. Any help,
> advice, pointers appreciated.
> 
> Thanks
> 
> 
> -- 
> To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe"
> as the Subject.
> 
> 


-- 
To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe"
as the Subject.

Reply via email to