Need help manipulating and replacing variables in a txt file

mic141414

Power Member
Joined
Jul 3, 2008
Messages
518
Reaction score
166
Hello,

Got a file with this line. times 100 with different values for each line.
username:password|127.0.0.1:8888|[email protected]|state_id=IT_state_06lfgyke6d7lcp5zt1r|device_string=28/9; 320dpi; 720x1468; samsung; SM-A102U; a10e; exynos7885; en_US; 239490550|locale=en_US|device_id=android-be0556003105326a|phone_id=791fb961-55d4-4f26-a349-ae60da1d150d|uuid=8e93ad38-2903-40c8-9af5-b4c2c2ebf9c8|adid=38e0a267-7f79-40f7-a4dc-25f6fc1903d3|sessionid=47200560288%3AjOYieAlC6xt9ki%3A27|mid=YHWRjwABAAEhdzVpQMhqTtBDQ_g-|csrftoken=JBpwiV7up1pVEkWZjkh7hZnYkSl0iNhO|ds_user_id=47200560288

one per line with different valies
I got 100 lines of that and i need to replace the first values username:password by 100 other values

It is IG accounts and i need to find a way to replace those 100 username:password by 100 other accounts so i can get a new file with the new IG accounts (username : password)

Any idea please? Thanks
 
Stuff like this can be done using Excel usually. If the text is formatted in an orderly fashion, copy-paste it into an empty Excel document. Choose the 'Text to Columns' feature, select the 'Other' delimiter, enter a colon and split the text into columns, so you'll have the usernames in column A. Because you have more than one type of delimiter, you need to repeat this with the pipe delimiter, so only the passwords stay in column B. When the data gets to the desired format (usernames in column A, passwords in column B), you can easily replace those columns.

https://www.extendoffice.com/documents/excel/1786-excel-split-text-by-space.html#a1

But probably it's even easier, if you split the lines by the pipe delimiter only, so the usernames and passwords stay in column A. Do this with both the data files, where you want to replace and what you want to use to replace with. So in both files column A contains the usernames and passwords separated by colon. When the data is formatted like that, you can replace column A with ease.
If you want the pipe delimiter back after you finished replacing, you can do that in Notepad++ using Search and Replace.
 
Last edited:
thank you

I got it on excel and replaced the 100 username password as they were in column A
BUT when I export the file (in txt as it was), they are like this
user1:password 127.0.0.1:8888 [email protected] state_id=IT_state_06lfgyke6d7lcp5zt1r device_string=28/9; 320dpi; 720x1468; samsung; SM-A102U; a10e; exynos7885; en_US; 239490550 locale=en_US device_id=android-be0556003105326a phone_id=791fb961-55d4-4f26-a349-ae60da1d150d uuid=8e93ad38-2903-40c8-9af5-b4c2c2ebf9c8 adid=38e0a267-7f79-40f7-a4dc-25f6fc1903d3 sessionid=47200560288%3AjOYieAlC6xt9ki%3A27 mid=YHWRjwABAAEhdzVpQMhqTtBDQ_g- csrftoken=JBpwiV7up1pVEkWZjkh7hZnYkSl0iNhO ds_user_id=47200560288

no more | so i cannot import into the sofware
sorry a newbie with excel and manipulation
 
<<If you want the pipe delimiter back after you finished replacing, you can do that in Notepad++ using Search and Replace. >>

Ok got it. I replace " " by " | " and file back to good format.

Thank you very much for your help
 
If you want to do it in python:
Code:
#Open file
f = open("your_file.csv")
lines = f.readlines()
f.close()

#Write out username:password to new file
f = open("out_file.csv")
for line in lines:
    f.write("{}:{}\n".format(*line.split("|")[0:2]))
f.close()
 
If you want to do it in python:
Code:
#Open file
f = open("your_file.csv")
lines = f.readlines()
f.close()

#Write out username:password to new file
f = open("out_file.csv")
for line in lines:
    f.write("{}:{}\n".format(*line.split("|")[0:2]))
f.close()
Thanks for sharing
 
Back
Top