SED based quote-comma converter
Posted in 1995
Here is a Quote-Comma file converter. There is awk, c, and whatever else versions out there, also. Just for someone's convenience. And, no, there is no cost for this. (Just playing it safe. Got to walk around here like there is egg shells everywhere.) --v-- SNIP --v-- SNIP --v-- SNIP --v-- SNIP --v-- SNIP --v-- SNIP --v-- # newdelim - quote-comma to delimiter converter # # This will convert MOST, not ALL, of the situations of quote-comma delimited # files. Which ones it won't get, I'm not sure, yet. if test $# -ne 3 ; then echo "usage: newdelim delimiter-to-use in-file out-file" exit 1 fi DELIM=$1 IN_FILE=$2 OUT_FILE=$3 if ! test -r $IN_FILE ; then echo "cannot open file: $IN_FILE" exit 1 fi # # First, backslash any delimiter in the data. Will not backslash already # backslashed chars. # sed -e "s/\\([^\\]\\)${DELIM}/\\1\\\\\\\\${DELIM}/g" \\ # # Next, change "," to delimiter char. # -e "s/\\",\\"/${DELIM}/g" \\ # # Then, change ," to delimiter char. # -e "s/,\\"/${DELIM}/g" \\ # # Change ", to delimiter char. # -e "s/\\",/${DELIM}/g" \\ # # Then, change commas between two numeric fields to delimiter char. # -e "s/\\([0-9]\\),\\([0-9]\\)/\\1${DELIM}\\2/g" \\ # # Next, remove any quotes at beginning of line. # -e "s/^\\"//g" \\ # # Almost done, remove any quotes at end of line. # -e "s/\\"$//g" \\ # # Lastly, add delimiter char at end of line. # -e "s/$/${DELIM}/g" < $IN_FILE > $OUT_FILE # eof --^-- SNIP --^-- SNIP --^-- SNIP --^-- SNIP --^-- SNIP --^-- SNIP --^-- Robert Minter Data Systems Support \\\\\\_/// Senior Software Engineer A Client Technologies Company ( _ _ ) E-Mail: rob@dssmktg.com Tel: 714.771.0454 (| ^ |) #include <disclaimer.h> Fax: 714.771.3028 \\`-'/ De Colores - Emmaus OC-13 SURF'S UP \\_/