How to add or remove spaces in text file

Hi Team,

I have a text file which i want to add spaces for few columns and remove spaces for few columns.
How to achieve this.

1 Like

Hi @RajeshT,
I think in this situation in can be difficult to automate this as each of element can vary. But we can thing it “the human way”. For example you could change the larger empty space for nothing (using ctrl+h in notepad). This will remove area you want to remove. Then for example you could change “COMM” for "COMM ". This will add you more space etc. Then finally you could use this shortcuts and type into activity to do the same from Studio. It’s just an idea :slight_smile:

1 Like

Hi @Pablito,

Actually the spaces came because i have converted the text file to excel file and did some validations(Removed some rows based on conditions) ,and then i have copied the excel values to text file which results the spaces in between.
Can you give an example using Type into how we will remove or add spaces.

Sure, it’s all about tricking it from notepad :wink:
I’ll give you short example. We have file like this:
image
Let’s do CTRL+H and change this long space for only one space (in “Find what:” I will put this long space and in “Replace with:” I will put just one space):
image
Then after clicking replace we have this:
image
Now I want to add more space after “aaaaaaa” (so I will replace "a " for "a "):
image
Result:
image
I think now you should now what I mean :slight_smile:

1 Like

Hi @Pablito ,
Thank you for you input’s,which works some part of the file.
But the problem is i have huge number of records ,can we use multiple cases in “Find what:”
Example:

Yes, you just need to catch the last part of each element to grab everything (assuming that each element have this part the same) and then use “replace all” button. For example in your screenshot this long serial number have at the every end the part “2869”. So you could just grab it and replace all “2869” for "2869 ". This will add you the space in every line :slight_smile: Just experiment.

2 Likes

Adding to what @Pablito mentioned, anything that is brought down from excel to notepad will usually have {TAB} as the separator/delimiter so it should be fairly straightforwardw ith some trial and error.

Or you can delimit the spaces with something like ‘|’ or ‘,’ and then process it further as and when required in the future. Just saying :slight_smile:

2 Likes

Hi @Pablito @Raghavendraprasad

I have multiple scenarios to find and replace ,instead of giving one by one can we give all conditions(Find what & Replace with) at a time in Replace window byusing comma(,) or Colon(:)?

Example:“171” replace with "172 " and “172” replace with "172 " and so on…

Unfortunately notepad is very simple tool. It can handle only one replace action at the time.

Hi @Pablito ,

Can we do it with Notepad++ using UiPath?

Regards,
Rajesh

Hi @RajeshT

I guess using a tool for string operations will seem counter intuitive as we have the full power of .NET for such manipulations.

If your data is limited (limited by capacity) by the memory setting of your VM/BOT run machine and it can handle large data (the data that you plan on manipulation, I hope the rows and columns are limited in number {Ideal scenario not more than 5 lakh rows}) then you can use string operations.

Data can be exported to Notepad and then ‘RedTextFile’ will import it again to memory and manipulation can be done.

Or if the scenario calls for more than 8 or 10 lakh rows and more than (at-least) 40 columns (with data) then it is better to use a custom code with StreamReader.

Hope this helps :slight_smile:

1 Like

I think that without any problem :slight_smile:

1 Like

HI @Raghavendraprasad

My file contains not more than 50,000 thousand records.

Data can be exported to Notepad and then ‘RedTextFile’ will import it again to memory and manipulation can be done.

Can you explain what type of tool you are talking about and how we can do with string operations.

Well,

You can directly use string manipulation using the ‘Uipath’ tool with assign statements as the whole text file will be read using the ‘Read Text file’ activity (forgive men if the exact activity name is not as such) and then you can replace or delete whatever strings you want to.

1 Like

Thank you @Raghavendraprasad for you inputs.
I understand that we can read the text file using “ReadTextFile” activity and based on conditions(using Regular Expressions) we can add or remove the spaces right.

Thanku @Pablito for your inputs.

1 Like