Replace column A with the content of column B

Get help with installation and running here.

Moderators: DataMystic Support, Moderators, DataMystic Support, Moderators, DataMystic Support, Moderators

Post Reply
ramin2000
Posts: 11
Joined: Wed Jun 02, 2010 12:02 am

Replace column A with the content of column B

Post 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?
User avatar
DataMystic Support
Site Admin
Posts: 2227
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: Replace column A with the content of column B

Post 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"
ramin2000
Posts: 11
Joined: Wed Jun 02, 2010 12:02 am

Re: Replace column A with the content of column B

Post by ramin2000 »

pipe text file
User avatar
DataMystic Support
Site Admin
Posts: 2227
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: Replace column A with the content of column B

Post 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|
websolprov
Posts: 1
Joined: Wed Oct 13, 2010 9:33 pm

Re: Replace column A with the content of column B

Post 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
User avatar
DataMystic Support
Site Admin
Posts: 2227
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: Replace column A with the content of column B

Post 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.
Post Reply