Compare contents of 2 files

190 views
Skip to first unread message

Matt R

unread,
May 13, 2013, 8:09:57 PM5/13/13
to tas...@googlegroups.com
There's a few different ways you could do it. For example, at the start, set a variable like %linenum to 1. Then, do a read line action for each file with the line specified as %linenum (this may not be necessary as I think Tasker automatically reads the next line each time you call the read line action on the same file). Then compare the variables where you stored the read line, do whatever actions, and then do a "go to" to the first read line action. Another way would be to read the whole file and split on the new line character and then do a for loop.

Matt

Bob Hansen

unread,
May 13, 2013, 9:19:51 PM5/13/13
to tas...@googlegroups.com
Here is a vert basic Task to read 2 files and compare line by line and write all matching lines to a file.
You add your file names.

File Compare (264)
A1: Open File [ File:File A Mime Type: ]
A2: Open File [ File:File B Mime Type: ]
A3: Open File [ File:OutFile Mime Type: ]
<Start>
A4: Anchor
A5: Read Line [ File:File A Line: To Var:%Filealine Continue Task After 
Error:On ]
A6: If [ %filealine ~ EOF ]
A7: Stop [ With Error:Off Task: ]
A8: End If
A9: Read Line [ File:File B Line: To Var:%Filebline Continue Task After 
Error:On ]
A10: If [ %filebline ~ EOF ]
A11: Stop [ With Error:Off Task: ]
A12: End If
A13: If [ %filealine ~ %filebline ]
A14: Write File [ File:OutFile Text:filealine Append:Off Add Newline:On ]
A15: End If
A16: Goto [ Type:Action Number Number:4 Label: ]

TomL

unread,
May 14, 2013, 8:11:26 AM5/14/13
to tas...@googlegroups.com
If you want a non-Tasker way to do it, I would recommend installing the busybox app and using the linux xommand diff at the shell prompt.

Tom

On Monday, May 13, 2013 1:39:18 PM UTC-4, Przemysław Płocieniczak wrote:
I would like to compare two txt files, line by line (each line is phrease consist of words and numbers) and if two lines matches, write that match into another file. I know i should use some kind of loop or maybe arrays but I stuck and have no idea what should I do. Any help would be much appreciated.

Przemysław Płocieniczak

unread,
May 14, 2013, 12:05:29 PM5/14/13
to tas...@googlegroups.com
Thanks. This work great but only if this two files has equal or second one has more lines.
Btw. what is the purpose of using Open File action?

Przemysław Płocieniczak

unread,
May 14, 2013, 12:11:00 PM5/14/13
to tas...@googlegroups.com
Thanks. I figured out that for my is better to split on the new line character but I don't understand how "for loop" works and example from tasker quide gives me no clue ;/ But will try to find more helpfull example.

Przemysław Płocieniczak

unread,
May 14, 2013, 12:15:36 PM5/14/13
to tas...@googlegroups.com
Thanks for pointing me another way to achive my goal. I already have installed busybox so will look into diff as you recommended.
Reply all
Reply to author
Forward
0 new messages