merge two files in to one file

kolli kolli wrote:
Can anyone tell me how to merge two files in to one file.
What do you mean by 'merge'? A couple of possible meanings include: - Concatenate the second file onto the end of the first. - Line by line merge; line of first file, followed by line of second and so on. - Byte by byte merge; byte from the first file, followed by a byte from the second and so on. Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/

all the lines of first file followed by all the lines of second file
On Tue, Oct 4, 2011 at 6:51 PM, Erik de Castro Lopo
kolli kolli wrote:
Can anyone tell me how to merge two files in to one file.
What do you mean by 'merge'? A couple of possible meanings include:
- Concatenate the second file onto the end of the first.
- Line by line merge; line of first file, followed by line of second and so on.
- Byte by byte merge; byte from the first file, followed by a byte from the second and so on.
Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

kolli kolli wrote:
all the lines of first file followed by all the lines of second file
Well, it can be as simple as: main :: IO () main = do data1 <- readFile "firstfile" data2 <- readFile "secondfile" writeFile "output" (data1 ++ data2) which should work fine for text files of arbitrary length. It won't however work for binary files (due to text encoding issues). For that try something like: import qualified Data.ByteString.Lazy as BSL main :: IO () main = do data1 <- BSL.readFile "firstfile" data2 <- BSL.readFile "secondfile" BSL.writeFile "output" (BSL.concat [data1, data2]) In both cases, Haskell's lazy evaluation means that the program does not need to read in the whole of each file, but will read both files in chunks as well as writing the output file in chunks. HTH, Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/

thanks a lot...
On Tue, Oct 4, 2011 at 7:24 PM, Erik de Castro Lopo
kolli kolli wrote:
all the lines of first file followed by all the lines of second file
Well, it can be as simple as:
main :: IO () main = do data1 <- readFile "firstfile" data2 <- readFile "secondfile" writeFile "output" (data1 ++ data2)
which should work fine for text files of arbitrary length. It won't however work for binary files (due to text encoding issues). For that try something like:
import qualified Data.ByteString.Lazy as BSL
main :: IO () main = do data1 <- BSL.readFile "firstfile" data2 <- BSL.readFile "secondfile" BSL.writeFile "output" (BSL.concat [data1, data2])
In both cases, Haskell's lazy evaluation means that the program does not need to read in the whole of each file, but will read both files in chunks as well as writing the output file in chunks.
HTH, Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/

I think this(merging two files) is same as concatenating two files..
On Tue, Oct 4, 2011 at 7:24 PM, Erik de Castro Lopo
kolli kolli wrote:
all the lines of first file followed by all the lines of second file
Well, it can be as simple as:
main :: IO () main = do data1 <- readFile "firstfile" data2 <- reFile "secondfile" writeFile "output" (data1 ++ data2)
which should work fine for text files of arbitrary length. It won't however work for binary files (due to text encoding issues). For that try something like:
import qualified Data.ByteString.Lazy as BSL
main :: IO () main = do data1 <- BSL.readFile "firstfile" data2 <- BSL.readFile "secondfile" BSL.writeFile "output" (BSL.concat [data1, data2])
In both cases, Haskell's lazy evaluation means that the program does not need to read in the whole of each file, but will read both files in chunks as well as writing the output file in chunks.
HTH, Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/

kolli kolli wrote:
I think this(merging two files) is same as concatenating two files..
Yes, what we are doing is concatenation. I would not call this merging at all. Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/

how to sort the values according to column or by date or by time or by
alphabetical order
* 3616 * 3556 2 11:49:43 /usr/bin/ps
*3332* 2676 1 Jul 18 /usr/bin/bash
*500* 2832 0 Jul 18 /usr/bin/bash
On Tue, Oct 4, 2011 at 8:20 PM, Erik de Castro Lopo
kolli kolli wrote:
I think this(merging two files) is same as concatenating two files..
Yes, what we are doing is concatenation. I would not call this merging at all.
Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

kolli kolli wrote:
how to sort the values according to column or by date or by time or by alphabetical order
* 3616 * 3556 2 11:49:43 /usr/bin/ps *3332* 2676 1 Jul 18 /usr/bin/bash *500* 2832 0 Jul 18 /usr/bin/bash
Unfortunately, that seems rather poorly formated and I susect that rather than parsing that as text you would want to use functions in System.Directory to read the directory into a list of structs and then sort that. Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/
participants (2)
-
Erik de Castro Lopo
-
kolli kolli