5 Replies Latest reply: Feb 23, 2018 3:15 PM by David Lundqvist RSS

    Replace

    David Lundqvist

      Hi,

      We are trying to import text files into a temporary textfile and post each "filedata" on a new row.

      The script does not replace "D180222" with "ABC" on any row in the "Tempdata" textfile

       

      Tempdata:

      LOAD

      Filename() as filnamn,

      Replace("@1:n",'D180222', 'ABC') as DatarowInfo

      FROM [lib://folder/D180222.*.txt]

      (fix, codepage is 28591, no labels);

       

      Thanks in advance

        • Re: Replace
          Sunny Talwar

          What exactly is this? @1:n, a field name? and in this field you want to replace D180222 with ABC?

          • Re: Replace
            Jahanzeb Hashmi

            look like it would be

            Replace ('D180222', 'D180222','ABC')

            if you want to do it through replace

             

              • Re: Replace
                Juraj Misina

                Hi,

                I have two ideas.

                1. I'm a fan of square brackets, try using those instead of double quotes for the @ notation:

                Replace([@1:n],'D180222', 'ABC') as DatarowInfo
                

                 

                2. try using preceding load, maybe the Replace() function got confused by the @ notation:

                Tempdata:
                LOAD
                filnamn,
                Replace(DatarowInfo,'D180222', 'ABC') as DatarowInfo
                ;
                LOAD
                Filename() as filnamn,
                [@1:n] as DatarowInfo
                FROM [lib://folder/D180222.*.txt]
                (fix, codepage is 28591, no labels);
                

                 

                Hope this helps.

                Juraj

              • Re: Replace
                David Lundqvist

                Thanks guys,

                I managed to figure this out by myself at last but thanks for your help.

                • Re: Replace
                  omar bensalem

                  Not sure what u want u mean but @1:n , but it seems to me that u want to replace every value of every field of ur table.

                  sthing like for i= to n do ... ?

                   

                  Well if that's the case :

                   

                  let's suppose u have this:

                  t:

                  col1,col2,col3,col4

                  value1x,value2x,value3x,value4x

                  value11x,value22x,value33x,value44x

                  value111x,value222x,value333x,value444x

                  value1111x,value2222x,value3333x,value4444x

                  value111111x,value22222x,value33333x,value44444x

                  ];

                   

                  and u want to replace every x in every column by ABC

                   

                  here what u do :

                   

                  t:

                  load RowNo() as row,* Inline [

                  col1,col2,col3,col4

                  value1x,value2x,value3x,value4x

                  value11x,value22x,value33x,value44x

                  value111x,value222x,value333x,value444x

                  value1111x,value2222x,value3333x,value4444x

                  value111111x,value22222x,value33333x,value44444x

                  ];

                   

                  final:

                  load row  Resident t;

                   

                  let nOffield=NoOfFields('t');

                   

                  for i=2 to $(nOffield)

                  LET Field = FieldName(i,'t');

                   

                  left join(final)

                  load row , Replace($(Field),'x','ABC') as $(Field) Resident t;

                  next i

                   

                  drop Table t;



                  Result:

                  Capture.PNG