Welcome to WebmasterWorld Guest from 54.196.208.6

Forum Moderators: bakedjake

Message Too Old, No Replies

Merge Log Files (txt format)

Merge text files into one

     
3:10 am on Dec 15, 2009 (gmt 0)

New User

5+ Year Member

joined:Mar 12, 2009
posts: 15
votes: 0


I log roll quite a bit and after collecting hundreds of txt files, I needed to combined these files into one. Not knowing unix or fancy vba, I had to find an app to do this.

After digging, I found bulk file merger. This neat little app managed to merge all my txt log files into one in a matter of seconds.
What a time saver....

12:30 pm on Dec 15, 2009 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10542
votes: 8


you can use the unix cat command for this.
here are some examples of usage:

cat file1 file2 file3 >bigfile (concatenates a list of files into one file)
cat *.txt >bigfile.txt (same but using wildcarding to list the files)
cat file.txt >>existingfile.txt (concatenating a file to the end of an existing file)

2:10 pm on Dec 15, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member wheel is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Feb 11, 2003
posts:5063
votes: 11


The stuff you can do from the command line in linux is crazy. The difficult part is knowing the commands :).

Doing search and replace/text finding type of things are crazy easy.

I'm no expert but I routinely use the two following:
grep -R string *
which looks recursively for 'string' in every file, down into the directory structure. Looking for a bit of code? just type that at the top of the directory and it'll find it for you.

The other one I use is a search and replace:
perl -p -i -e 's/stringa/stringb/g' *
which replaces all occurrences of stringa with stringb. (I think this is called the perl 'pie' or something like that).

11:54 pm on Dec 15, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 20, 2004
posts:1475
votes: 0


wheel ... if you like the PERL, you ought'a love sed:

sed -i 's/searchfor/replacewith/g' *

Just sayin' ...

11:37 am on Dec 16, 2009 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10542
votes: 8


linux 101 day 1 includes these commands:
man
ls
rm
cat
grep
sed
for

a few of these commands with options open up another dimension:
grep -i
grep -v
grep -l
sed -n

be very (VERY) careful with:
rm -r
always (ALWAYS) do this first:
ls -r

then learn these operators:
(that would be the vertical bar which gets converted to a broken bar in this forum - uppercase backslash on a typical keyboard)
>
>>

that might cover at least 80-90% of your daily needs

if you also learn awk you can do some very sophisticated text processing without writing a program per se.