How can I delete a specific line in a csv file with iMacros?

Discussions and Tech Support related to the iMacros Firefox Add-on, including the built-in Javascript scripting interface for playing .js files.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
ThePoro
Posts: 15
Joined: Sat Mar 09, 2019 7:23 am

How can I delete a specific line in a csv file with iMacros?

Post by ThePoro » Sat Mar 09, 2019 7:37 am

I already have a code to read csv file below and detect what profile is running to access the website.
"profile1","google.com"
"profile1","youtube.com"
"profile2","facebook.com"

They can read the file perfectly but my problem is I don't know how to delete a specific line for the next time my code run.
Does anyone know how to delete a specific line or change it like this? for the next time my code run? Thank you

"profile1","youtube.com"
"profile2","facebook.com"

or
"done","profile1","google.com"
"profile1","youtube.com"
"profile2","facebook.com"

iMacros 8.9.7
Firefox 56
Windows 10
Last edited by ThePoro on Tue Mar 12, 2019 12:53 am, edited 1 time in total.
chivracq
Posts: 8626
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How can I delete a specific line in a csv file with imacors?

Post by chivracq » Sat Mar 09, 2019 12:12 pm

ThePoro wrote:
Sat Mar 09, 2019 7:37 am

Code: Select all

iMacros 8.9.7
Firefox 56 
Windows 10

I already have a code to read csv file below and detect what profile is running to access the website.
"profile1","google.com"
"profile1","youtube.com"
"profile2","facebook.com"

They can read the file perfectly but my problem is I don't know how to delete a specific line for the next time my code run.
Does anyone know how to delete a specific line or change it like this? for the next time my code run? Thank you

"profile1","youtube.com"
"profile2","facebook.com"

or
"done","profile1","google.com"
"profile1","youtube.com"
"profile2","facebook.com"

iMacros 8.9.7
Firefox 56
Windows 10
You can't "directly"... iMacros can only append new Content (new Rows) to an existing File.

Depending a bit on how many Rows you have in your '.CSV' and if hard-coding all Row-Numbers is "doable" in an '.iim', or if you are using a '.js' Script, it would be possible to add an extra Routine in your Script where you would read your '.CSV' Row by Row, store that Content in Memory or in some Temp File, fire a 'FILEDELETE' on your File once its whole Content has been read, to then recreate the File and write its new Content to it.

Maybe a bit "easier" would be to use some mini-Temp File storing only the Row_Nb (to use for '!DATASOURCE_LINE') to "remember" which Row in the '.CSV' was last processed... and to start looping only from the new one. (Using the same Mechanism: Read that File, delete it, and recreate it.)

[Ugly Typos on "iMacros" in your Thread Title btw...]
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
chivracq
Posts: 8626
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How can I delete a specific line in a csv file with imacors?

Post by chivracq » Sat Mar 09, 2019 12:36 pm

Hum, and another Technique would be to store the whole Content of your '.CSV' as only 1 Cell (by manually adding an extra Double-Quote at the complete beginning + complete end from 'Notepad') that your Script will be able to retrieve/read with just one single '{{!COL1}}', to then using 'EVAL()' to manipulate that Content, before deleting and recreating the File to save the new Content.

You would also need to add an extra Column on the Left or Right of your '.CSV' to use as a "Separator" (with "##" for example) to be able to re-split the whole Content of that one Cell into your original Rows, and you would use the original '!LOOP' to access each Row for the Index on the 'split('##')[i]'. (And '!LOOP' and 'i' are "synchronized" if you place that extra Col on the Left, as '[i]' starts at "[0]".)
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
ThePoro
Posts: 15
Joined: Sat Mar 09, 2019 7:23 am

Re: How can I delete a specific line in a csv file with iMacros?

Post by ThePoro » Mon Mar 11, 2019 2:51 pm

Thank you for your help, but I already have another plan for my work. So thank you for helping me this situation.
Last edited by ThePoro on Tue Mar 12, 2019 2:12 am, edited 1 time in total.
chivracq
Posts: 8626
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How can I delete a specific line in a csv file with imacors?

Post by chivracq » Mon Mar 11, 2019 3:10 pm

ThePoro wrote:
Mon Mar 11, 2019 2:51 pm
Thank you for your help, but I already have another plan for my work. So thank you for helping me this situation.
Yeah well, then share your "other plan for your work" to make this Thread also useful for other Users and the Forum Community... :idea:
Sharing your Solution and/or Final Script also belong(s) to my "correct Use of the Forum" Criteria... :wink:

+ I asked you to correct the ugly Typo(s) in your Thread Title but you didn't comply... Another of my "Criteria"... :roll:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
ThePoro
Posts: 15
Joined: Sat Mar 09, 2019 7:23 am

Re: How can I delete a specific line in a csv file with iMacros?

Post by ThePoro » Mon Mar 11, 2019 3:36 pm

My plan is I rewrite every time it accesses a website to another csv file. and then let it compare file 1 and file 2 if it coincides, the loop keeps running and read another line in file 1. Oh can you please tell me what is ugly typo?
And may I ask you another question?
How can I save as only var3 and var4? I don't want to save extract

Code: Select all

SET !EXTRACT_TEST_POPUP NO
TAG POS={{!var1}} TYPE=TD ATTR=TXT:something* extract=txt
SET !VAR4 EVAL ("var string=\"{{!EXTRACT}}\"; string.substr(5,);")
TAG POS={{!var2}} TYPE=DIV ATTR=TXT:Verify* extract=txt
SET !VAR3 EVAL ("var string=\"{{!EXTRACT}}\"; string.substr(85,7);")
SAVEAS TYPE=EXTRACT FOLDER=C:\AMZ FILE=VERIFY-CODE.csv
Last edited by ThePoro on Tue Mar 12, 2019 2:11 am, edited 1 time in total.
chivracq
Posts: 8626
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How can I delete a specific line in a csv file with imacors?

Post by chivracq » Mon Mar 11, 2019 4:23 pm

ThePoro wrote:
Mon Mar 11, 2019 3:36 pm
My plan is I rewrite every time it accesses a website to another csv file. and then let it compare file 1 and file 2 if it coincides, the loop keeps running and read another line in file 1. Oh can you please tell me what is ugly typo?
Hum, OK, that's a way to "do it" indeed... You could have posted that Script, but OK, never mind, that's "good enough" for the "Quality" of your Thread...

Well "Typo" = Spelling Mistake... And I already indicated in my first Reply where exactly, read that Post again...

ThePoro wrote:
Mon Mar 11, 2019 3:36 pm
And may I ask you another question?
How can I save as only var3 and var4? I don't want to save extract

Code: Select all

SET !EXTRACT_TEST_POPUP NO
TAG POS={{!var1}} TYPE=TD ATTR=TXT:something* extract=txt
SET !VAR4 EVAL ("var string=\"{{!EXTRACT}}\"; string.substr(5,);")
TAG POS={{!var2}} TYPE=DIV ATTR=TXT:Verify* extract=txt
SET !VAR3 EVAL ("var string=\"{{!EXTRACT}}\"; string.substr(85,7);")
SAVEAS TYPE=EXTRACT FOLDER=C:\AMZ FILE=VERIFY-CODE.csv
I'll answer that one after you've corrected the Typos...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
chivracq
Posts: 8626
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How can I delete a specific line in a csv file with imacors?

Post by chivracq » Mon Mar 11, 2019 7:09 pm

And @biaconhieu, yep, I've seen your Post..., but I won't approve it because the Forum Language is English and you keep posting in Vietnamese...! :roll:
I won't grant you Access to the Forum if posting in English is "too complicated" for you, sorry!, a simple C&P in 'Google Translate' already does "a very good job"... :roll:

(I will post your Post/Solution though (hum..., maybe...! :twisted: ) after @OP will have complied with my "Request" to correct the Typos in their Thread Title, a bit "tired" of repeating/asking the same "Things"..., grrr...!! :shock: )

>>>

EDIT:
=> With that Post (disapproved) from @biaconhieu, with the Text parts in Italic translated from Vietnamese into English by 'GoogleTranslate'...:
Re: How can I delete a specific line in a csv file with imacors?
Post by biaconhieu » 11/03/2019 - 18:35
ThePoro wrote: ↑
09/03/2019 - 08:37
I already have a code to read csv file below and detect what profile is running to access the website.
"profile1","google.com"
"profile1","youtube.com"
"profile2","facebook.com"

They can read the file perfectly but my problem is I don't know how to delete a specific line for the next time my code run.
Does anyone know how to delete a specific line or change it like this? for the next time my code run? Thank you

"profile1","youtube.com"
"profile2","facebook.com"

or
"done","profile1","google.com"
"profile1","youtube.com"
"profile2","facebook.com"

iMacros 8.9.7
Firefox 56
Windows 10
Hi!
If you want to delete the line in .txt or .csv file, use javascript
This is the code you can reference, the code will delete the first line of the .txt file
I like this way, because there's no need to create additional .log files


imacro 8.9.7
firefox 56

Code: Select all

var a = imns.FIO.openNode("D:\\test.txt");
var b = imns.FIO.readTextFile(a).split("\r\n").slice(1).join("\r\n");
var c = imns.FIO.writeTextFile(a, b);
p / s: sorry, I can't speak English :(
Last edited by chivracq on Tue Mar 26, 2019 7:07 am, edited 1 time in total.
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
ThePoro
Posts: 15
Joined: Sat Mar 09, 2019 7:23 am

Re: How can I delete a specific line in a csv file with iMacros?

Post by ThePoro » Tue Mar 12, 2019 12:55 am

Oh I see what happened with my title, I've already corrected it.
ThePoro
Posts: 15
Joined: Sat Mar 09, 2019 7:23 am

Re: How can I delete a specific line in a csv file with iMacros?

Post by ThePoro » Tue Mar 12, 2019 2:10 am

chivracq wrote:
Mon Mar 11, 2019 4:23 pm
ThePoro wrote:
Mon Mar 11, 2019 3:36 pm
My plan is I rewrite every time it accesses a website to another csv file. and then let it compare file 1 and file 2 if it coincides, the loop keeps running and read another line in file 1. Oh can you please tell me what is ugly typo?
Hum, OK, that's a way to "do it" indeed... You could have posted that Script, but OK, never mind, that's "good enough" for the "Quality" of your Thread...

Well "Typo" = Spelling Mistake... And I already indicated in my first Reply where exactly, read that Post again...

ThePoro wrote:
Mon Mar 11, 2019 3:36 pm
And may I ask you another question?
How can I save as only var3 and var4? I don't want to save extract

Code: Select all

SET !EXTRACT_TEST_POPUP NO
TAG POS={{!var1}} TYPE=TD ATTR=TXT:something* extract=txt
SET !VAR4 EVAL ("var string=\"{{!EXTRACT}}\"; string.substr(5,);")
TAG POS={{!var2}} TYPE=DIV ATTR=TXT:Verify* extract=txt
SET !VAR3 EVAL ("var string=\"{{!EXTRACT}}\"; string.substr(85,7);")
SAVEAS TYPE=EXTRACT FOLDER=C:\AMZ FILE=VERIFY-CODE.csv
I'll answer that one after you've corrected the Typos...
Can you help me with this?
ThePoro
Posts: 15
Joined: Sat Mar 09, 2019 7:23 am

Re: How can I delete a specific line in a csv file with iMacros?

Post by ThePoro » Wed Mar 13, 2019 10:20 am

I've already known how to do that.
This is js file.

Code: Select all

iimPlay("var1.iim");
var A = iimGetLastExtract(1)
iimPlay("var2.iim");
var B = iimGetLastExtract(1)
iimSet("var1",A);
iimSet("var2",B);
iimPlay("save-var.iim");
}
var1.iim

Code: Select all

SET !REPLAYSPEED FAST
SET !EXTRACT_TEST_POPUP NO
TAG POS=1......(your code)...... extract=txt
SET !VAR4 EVAL ("var string=\"{{!EXTRACT}}\"; string.substr(5,);")  //this is how I split what I want to get
Set !EXTRACT NULL
Add !EXTRACT {{!VAR4}}
var2.iim
Same with var1.iim with another variable to save to csv file
save-var.iim

Code: Select all

SET !REPLAYSPEED FAST
Add !EXTRACT {{!var1}}
Add !EXTRACT {{!var2}}
SAVEAS TYPE=EXTRACT FOLDER=C:\ FILE=VAR.csv
Post Reply