Re: SED: Insert Token at specific points

From: Alan Connor (zzzzzz_at_xxx.yyy)
Date: 06/30/05


Date: Thu, 30 Jun 2005 10:38:39 GMT

On comp.unix.shell, in <42C3BDDB.90304@gmx.de>, "Thorsten Knopel" wrote:
>
>
> Hello
>
> I hada little problem
>
> we Data (CSV) files with following schema
>
> DATA "Karl" "2" "OLGA" "4" "5" "6" "TOTO" ... "70"
> DATA "1" "MEL" "URGA" "4" "SEPP" "6" "TOT" ... "70"
>
>
> And we want insert empty values at position 3 and 5
>
> DATA "Karl" "2" "OLGA" "" "4" "5" "" "6" "TOTO" ... "70"
> DATA "1" "MEL" "URGA" "" "4" "SEPP" "" "6" "TOT"... "70"

sed -n 's/^\(DATA \)\(\"[^"]*\"\)\( \"[^"]*\" \)\(\"[^"]*\"\)\
\( \"[^"]*\" \)\(\"[^"]*\"\)\ \(.*\)/\1\2 \3 \"\" \5 \"\" \
\7/p' inputfile > outputfile

# copy the above literally, making sure there is a newline
# immedialtely after the final "\" on each line.

mv outputfile inputfile # AFTER testing carefully!

I think that'll do the job. If not, a little playing with it will
make it work.

>
> A simple patter didnt do a ,because we have lines of 50 to 70
> Values, and the pattern will be to big.
>
> How we can do this simply with a sed script ?
>
>
> Thanks for you Help
>

Sure,

AC



Relevant Pages

  • Re: SED: Insert Token at specific points
    ... >> I hada little problem ... >> we Data (CSV) files with following schema ...
    (comp.unix.shell)
  • Incomplete DO/SELECT/IF Error, not sure why!
    ... Arg inputFile outputFile ... SCHEMA = 'CREATE SCHEMA' ... CALL PARSE ...
    (comp.lang.rexx)
  • Exportieren mit ISQL
    ... Das Inputfile sieht so aus: ... Im Outputfile steht nun in der ersten Zeile die Spaltennamen und in der ... Detlef ...
    (microsoft.public.de.sqlserver)
  • Re: AWK question
    ... >> I am having a bit of trouble trying to write an awk command that ... >' inputfile> outputfile ...
    (comp.unix.shell)
  • Re: AWK question
    ... >> I am having a bit of trouble trying to write an awk command that ... >' inputfile> outputfile ...
    (comp.unix.shell)