sort a logfile


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sort a logfile
# 1  
Old 06-17-2004
Data sort a logfile

Hi experts,
I need help to sort a big logfile.
logfile:

-------
67712 dkjd
jd jj jjjj
------
kjkj
jhjh kkk yggg
lll hhh gffgf jj
--------
i
kkk
kllkkl
-------

Now I want every think between the "------" in one line.
Normaly with paste no problem but you can see that the number of lines between "-----"
are different.

thanks joerg
# 2  
Old 06-17-2004
Try this:

Code:
cat logfile | perl -e 'while (<STDIN>) {if (!/-\n$/) {chomp;} if (/^-/) {print "\n";} print $_;}'

If a line does not end with '-', get ride of the \n, if a line starts with '-', then print a \n before it.
# 3  
Old 06-17-2004
MySQL thanks

Thanks for this replay it works well.

You use perl to do this job.
Is there a internet side i can learn thinks about this language.

Thanks a lot joerg
# 4  
Old 06-17-2004
Re: thanks

Quote:
Originally posted by joerg
Is there a internet side i can learn thinks about this language.
There is a vast amount of information about Perl online. http://www.perl.org is a good place to start. Another good resource is http://perlmonks.org and http://forums.devshed.com
# 5  
Old 06-17-2004
Re: thanks

Quote:
Originally posted by joerg
Thanks for this replay it works well.

You use perl to do this job.
Is there a internet side i can learn thinks about this language.

Thanks a lot joerg

I personally use http://www.perldoc.com for my own references. The perl manual pages are very well written and organized.

As for using perl for extended purposes (more then simple text parsing), http://search.cpan.org is the place for perl modules that will let you do pretty much anything.
# 6  
Old 06-22-2004
Data

Wy isent it possible to use tail -f instead of cat or more ?

Thanks and best regards joerg
# 7  
Old 06-22-2004
Code:
tail -f logfilename | perl -e 'while (<STDIN> ) {if (!/-\n$/) {chomp;} if (/^-/) {print "\n";} print $_;}'

That should work. The while(<STDIN>) is waiting for an EOF, you may want to disable buffering* in perl as well, this can be done with:

Code:
tail -f logfilename | perl -e '$|=1; while (<STDIN> ) {if (!/-\n$/) {chomp;} if (/^-/) {print "\n";} print $_;}'



* $|=1 doesn't really disable buffering, it just automaticly flushes the output.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Logfile monitoring with logfile replacement

Bonjour, I've wrote a script to monitor a logfile in realtime. It is working almost perfeclty except for two things. The script use the following technique : tail -fn0 $logfile | \ while read line ; do ... some stuff done First one, I'd like a way to end the monitoring script if a... (3 Replies)
Discussion started by: Warluck
3 Replies

2. Shell Programming and Scripting

Logs from logfile

Hi Team, Have to write a shell script to pick only 1 hr logs from the generated logfile and send it to other logfile. Thanks & Regards, Indu (3 Replies)
Discussion started by: indira_s
3 Replies

3. Shell Programming and Scripting

Sort help: How to sort collected 'file list' by date stamp :

Hi Experts, I have a filelist collected from another server , now want to sort the output using date/time stamp filed. - Filed 6, 7,8 are showing the date/time/stamp. Here is the input: #---------------------------------------------------------------------- -rw------- 1 root ... (3 Replies)
Discussion started by: rveri
3 Replies

4. Shell Programming and Scripting

Help with sort word and general numeric sort at the same time

Input file: 100%ABC2 3.44E-12 USA A2M%H02579 0E0 UK 100%ABC2 5.34E-8 UK 100%ABC2 3.25E-12 USA A2M%H02579 5E-45 UK Output file: 100%ABC2 3.44E-12 USA 100%ABC2 3.25E-12 USA 100%ABC2 5.34E-8 UK A2M%H02579 0E0 UK A2M%H02579 5E-45 UK Code try: sort -k1,1 -g -k2 -r input.txt... (2 Replies)
Discussion started by: perl_beginner
2 Replies

5. UNIX for Dummies Questions & Answers

writing to a logfile

I cannot get anything to go to my log. This is what i see on my screen when i run my korn shell. cd ok, cwd=/export/home/tsp_inst/TSP pget: /nas4/edata/tsp/rawdata/test2.gz: File exists But i cant get it to write it to my log. cd /this/is/my/newdirectory lftp -e 'pget -c -n 4... (1 Reply)
Discussion started by: tyngsboro
1 Replies

6. UNIX for Advanced & Expert Users

Script to sort the files and append the extension .sort to the sorted version of the file

Hello all - I am to this forum and fairly new in learning unix and finding some difficulty in preparing a small shell script. I am trying to make script to sort all the files given by user as input (either the exact full name of the file or say the files matching the criteria like all files... (3 Replies)
Discussion started by: pankaj80
3 Replies

7. Shell Programming and Scripting

looking for string in logfile

I have a shell script that used to look for a particular sting in the last line of a log file. Howeve this string now has moved to the 3rd or 4th line from bottom. Can anyone point me to how i easiest chage this one to look within the last frew lines (5 or so) for the particular string rather... (6 Replies)
Discussion started by: jjlinux
6 Replies

8. UNIX for Dummies Questions & Answers

Logfile manipulation

Hi First of all I m a complete newbie to Linux ... just started working on it exactly a week ago. I know a bit of programming in C but not very good in it.:D I was given task in my workplace and need some help nAJLR02F030879 9805 Thu Nov 19 13:27 <customerservice@YYY.com> ... (2 Replies)
Discussion started by: abilash.amara
2 Replies

9. Shell Programming and Scripting

logfile

hi iam new of the ksh script.iwant in formation of how to call in logfile in ksh scripts. if the meaning in ksh. please help me thanks naveen.g (1 Reply)
Discussion started by: naveeng.81
1 Replies

10. Shell Programming and Scripting

last month's logfile

hi friends I need a shell script which will do the following Task Enter the month : if you enter 1 then it ll show you last 1 month's (starting from today).log file in the current directry. if you enter 4 then it ll show you last 4 month's (starting from today).log file in the current... (2 Replies)
Discussion started by: deep_kol
2 Replies
Login or Register to Ask a Question