Page 1 of 1

Replace column A with the content of column B

Posted: Wed Sep 15, 2010 2:09 am
by ramin2000
Hi all
The following maybe very easy to do but I cant seem to get it done.

Every time ### shows up in column A replace it with the content of column B

Any ideas?

Re: Replace column A with the content of column B

Posted: Thu Sep 16, 2010 9:51 am
by DataMystic Support
Are the columns in a CSV file? Tab file? Or just fixed width columns? Are they adjacent columns?

Assuming adjacent fields in a CSV delimited file, find EasyPattern

Code: Select all

"###","[ capture(1+chars) ]"
Replace with

Code: Select all

"$1","$1"

Re: Replace column A with the content of column B

Posted: Thu Sep 16, 2010 1:13 pm
by ramin2000
pipe text file

Re: Replace column A with the content of column B

Posted: Fri Sep 17, 2010 8:16 am
by DataMystic Support
Are the pipe columns adjacent?

If so, use EasyPattern

Code: Select all

|###|[ capture(1+chars) ]|
Replace with

Code: Select all

|$1|$1|

Re: Replace column A with the content of column B

Posted: Wed Oct 13, 2010 9:57 pm
by websolprov
Hi Simon,

Long time no speak, I have data along the lines of the following:
01/10/2010;00:00:00:025;T;AP0Y;235;3;f2=4628;f3=2;f108=19;f1=599;f30=4555;f33=8159;f243=4616
01/10/2010;00:00:00:025;T;AP0Y;235;3;f2=4628;f3=2;f108=19;f1=599;f30=4556;f33=8161;f243=4616
01/10/2010;00:00:00:541;T;AP0Y;235;3;f2=4629;f3=1;f108=19;f1=599;f30=4557;f33=8162;f243=4616

This has been extracted with a "restrict lines to matching" ^(0[1-9]|[1-2][0-9]|3[0-1])/(0[1-9]|[1-2][0-9]|3[0-1])/[0-9]{4}\;([0-9]{2}:){3}([0-9]{3})\;T\;[\@0-9a-zA-Z]*\;[0-9]{1,3}\;[0-9]{1,2}\;

What I need to do is take each of the tags and consolidate them into columns, given the random use of tags and the fact they can be in any order perhaps OUTSIDE the existing column range, then move the "blank columns" left followign the data being moved. There you should end up with f1=x in the same column regardless of order in original data, the f2= in the same column and so forth. I was thinking of a "move column based on "(f2=[0-9]{1,4})" for each of the tag pairs I need but I can only see move nth column etc.

Can you point me in the right direction please? Thanks,

Alex

Re: Replace column A with the content of column B

Posted: Thu Oct 14, 2010 7:42 am
by DataMystic Support
Hi Alex,

The only way you can do this is with a Scripting filter that splits out the string using semi-colons (;), examines each column for a fXXX=YYYY value, and if found, loads the f value into an array. At the end of the line, it then needs to spit out every single column from 1 to the maximum value of XXXX, inserting dummy values where needed.