Copy/print all lines between pattern is found in .log files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy/print all lines between pattern is found in .log files
# 8  
Old 11-20-2012
Quote:
Originally Posted by APT_3009
Code:
#!/bin/ksh
###finding pattern in multiple log files
ll -rt *.log | tr -s "[:space]" " " | cut -d" " -f9 > Logfiles2check
rm -f OutputFile.txt
for each_file in `cat Logfiles2check`
do
awk '/begin/,/Total:/' ${each_file} >> OutputFile.txt
echo "\n\n" >> OutputFile.txt
done

I already removed your previous post on the grounds that the code in it was shockingly bad. There was no need to repost is.
# 9  
Old 11-20-2012
I have tried both commands

Code:
Code:
awk '/begin/,/Total:/' 001.log >> OutputFile.txt

sed '/begin/,/Total:/' 001.log >> OutputFile.txt

and they both print full the file back
# 10  
Old 11-20-2012
The first one would.

The second one is not the command I showed you!
# 11  
Old 11-20-2012
the first one print the whole file back

Code:
sed '/alt/,/Total/!d' 013.log > Outputfile.txt


Last edited by Scott; 11-20-2012 at 04:06 PM.. Reason: Code tags, PLEASE
# 12  
Old 11-20-2012
Please post the contents, or a representative sample, of that file.

Say which OS you are using, including version, and what shell you are using.

And please tell me now if it's homework, before we go any further.
# 13  
Old 11-20-2012
pffffff..... found the problem. It needed a space before the first pattern.

Code:
 sed '/ begin/,/Total:/!d' 001.log > Outputfile.txt

Tnx Smilie

Last edited by Scott; 11-20-2012 at 04:15 PM.. Reason: Code tags
# 14  
Old 11-20-2012
That's highly unlikely. Adding anything literal to a regular expression reduces the likelihood of a match. It could never increase the likelihood.

edit: Having not seen your input file, everything is likely...

Perhaps you could better describe the starting pattern. i.e. like > begin.

Last edited by Scott; 11-20-2012 at 04:18 PM.. Reason: edited
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies

2. UNIX for Dummies Questions & Answers

awk - (URGENT!) Print lines sort and move lines if match found

URGENT HELP IS NEEDED!! I am looking to move matching lines (01 - 07) from File1 and 77 tab the matching string from File2, to File3.txt. I am almost done but - Currently, script is not printing lines to File3.txt in order. - Also the matching lines are not moving out of File1.txt ... (1 Reply)
Discussion started by: High-T
1 Replies

3. Shell Programming and Scripting

Print n lines from top and n lines from bottom of all files with .log extenstion

Oracle Linux 6.4 In a directory I have more than 300 files with the extension .log I want the first 5 and last 5 lines of these .log files to be printed on screen with each file's name. Expected output : Printing first 5 and last 5 lines of FX_WT_Feb8_2014.log !! Authentication... (7 Replies)
Discussion started by: kraljic
7 Replies

4. Shell Programming and Scripting

Print character after pattern found

Hi Gurus, i need your help to create a script the will print a characters after the pattern was found. Sample lines are below: My birthday:"1977-16-07", My birthday:"1975-16-07" My birthday:"1970-16-07". My patter should be "birthday:", then i want to print the following characters which... (18 Replies)
Discussion started by: scripter123
18 Replies

5. Shell Programming and Scripting

Print first 20 lines from all .log files

RHEL 5.8 In a directory I have more than 200 files with the extension .log Using head command I want to print first 20 lines of each log file. For each .log file, it should print like below Printing first 20 lines of : GRP_error_April29.log Apr 29 04:02:05 raptor03b syslogd 1.4.1:... (4 Replies)
Discussion started by: John K
4 Replies

6. Shell Programming and Scripting

awk to print all lines after a pattern is found

Is there a way with aw to print all lines after a string is found There is a file like this ....... ........ 2012/19/11 :11.58 PM some data lne no date 2012/19/11 :11.59 PM some other data 2012/20/11 :12.00 AM some other data some line without dates some more lines without dates... (8 Replies)
Discussion started by: swayam123
8 Replies

7. Shell Programming and Scripting

Need one liner to search pattern and print everything expect 6 lines from where pattern match made

i need to search for a pattern from a big file and print everything expect the next 6 lines from where the pattern match was made. (8 Replies)
Discussion started by: chidori
8 Replies

8. Shell Programming and Scripting

print next word after found pattern

Hi all, I'd like to print the next word after a found pattern. example text: word1 word2 word3 word4 pattern word5 pattern word1 word2 word3 word4 word1 word2 pattern word4 basiclly the word after pattern. Thanks (9 Replies)
Discussion started by: stinkefisch
9 Replies

9. Shell Programming and Scripting

copy lines from log files based on timestamp and sysdate

I'm looking for a command or simple script that will read lots of audit log file (*.aud) in log fold every 10 minutes, and will output to one file based on sysdate - 10 minutes. assume the script is run at 11:12:20, and it should grep the line from Wed Jun 17 11:02:43 2009 to end of file. after... (4 Replies)
Discussion started by: percvs88
4 Replies

10. Shell Programming and Scripting

copy lines from log files based on timestamp and sysdate

I am sorry to repost this question. it was not clear, and I had the meeting and didn't response the question on time. I do really need help and appreciate your help very much. I'm looking for a simple shell script that will read lots of audit log file (*.aud) in a log fold every 10 minutes,... (1 Reply)
Discussion started by: percvs88
1 Replies
Login or Register to Ask a Question