Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Please use [code][/code] tags around your code to keep formatting and make it easier to read
As you are predominantly using awk and grep to do the hard yards, I would suggest re-writing into a single awk script.
There is no real reason for all the temp files and using a for loop is the wrong process for reading a file, which of course is nullified if you do it all in awk anyway
There is no real reason for all the temp files and using a for loop is the wrong process for reading a file, which of course is nullified if you do it all in awk anyway
cat and cut are redundant with awk. But in general, since you are using bash, you can probably eliminate the temprory files and use process substitution instead.
akk!, it is difficult to know what your script does because we don't see the log files, and what the desired result is.
you don't need to convert it all to awk (and nobody is likely to do it for you), but show us something we can work with.
code tags, working script, example input, example output, and desired output.
We have no idea what is this good for, because we don't know the format of the input file and don't know what do you want to collect. But this chain can be definitely implemented in one single awk, which will make it much faster and probably more readable too.
The second line looks like processing the result of the first line, probably you can pipe the two lines into one and no need to save that file at all. cat is not required, therefore you only need to add the awk to your pipe chain, which - again - can be simplified - and use altogether one awk script.
the for/cat/grep loop will work on the result and will filter the original file, but the mentioned awk can do this too, without this loop structure.
But again, without knowing what is in the log file (exactly) and what do you want to filter out (by example) will be hard to go further.
So please give us more details...
can you restructured above script as per your suggested way?
that will really helpful for me.
You have been given several suggestions as well as have been asked for clarification about what your script does, including a request for sample I/O.
LQ members are not a help desk and are not here to provide you with code. The purpose of the LQ site is that we are here to help you learn by you completing your work with our suggestions.
Please provide the feedback and information that members have requested.
Quote:
Originally Posted by akk!
There is no real reason for all the temp files and using a for loop is the wrong process for reading a file, which of course is nullified if you do it all in awk anyway
I am talking about this.
This is very difficult to tell because your description of the problem is incomplete and vague. Please try to explain your problem more clearly. Once again, suggest you illustrate sample input and output to clarify what you're asking about.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.