I have a log file which contains a big text lines. I wanted to keep the important lines and remove the unwanted lines from the big text file. I am new in UNIX. I would appreciate if someone can help me write UNIX script to remove the unwanted line from the text file.
Personally, I think that this is a job that calls for Global Regular Expression Print(ing) - grep. Peter's suggestion is closer to what you originally requested, insofar as you would end up with a program that is relatively easy to read and maintain, even by people who don't do much shell scripting. Whereas using grep will result in a more concise script. If you are interested in going the grep route, you may want to look at the Wikipedia article on grep, especially the examples.
It's worth noting, however, that for the sample message, that the app has had a simple data validation error. For a production app, that should have been intercepted and logged more concisely, since there's no need for a stack trace and there is conversely the possibility that a sufficiently-aware "catch" clause in a Struts action processor might be able to provide more useful context to the message that actually got logged. Assuming that invalid data even needs logging in the first place.
An IDE is no substitute for an Intelligent Developer.
Sam Saha wrote:I have a log file which contains a big text lines. I wanted to keep the important lines and remove the unwanted lines from the big text file.
... ... ...
I wanted the output to be like this:
From the shell prompt (console), you can use simple grep command like this: (assumed the log file is "server.log" )
It will filter out all the lines with "at " strings, hence results to your expected text.
To write the output text to a new logfile (says, it's "newfile.log"), simply add like following:
We can also achieve the expected result with sed, awk, perl, vim, ... but I think grep is simple enough :-)