Grep error in Bashscript
While running bashscript i.e. checkdump I am getting error.
Quote:
Quote:
What am I missing ? Do i have to provide any parameter in grep |
Two things I noticed - I am no expert so this could just be the way I learned it.
Should have ticks `` in here: dt=`date | awk '{print $2}' ` Why the pipe to sh?" ls -ltr | tail -1 | awk '{print "cat " $9}' | grep $dt Was there something you were trying to accomplish when piping it to sh? |
Try:
Code:
#!/bin/bash Code:
MY_VAR='asdf' Forrest |
@ADxD_7
Yup I forgot backticks actually awk '{print "cat " $9}' output is cat filename so that output to be filtered with variable mentioned above. Thnx buddy @forrestt Thnaks buddy, You have mentioned very imp. points & easy way to do things. Thanks a lot again I have edited script according to changes mentioned above, it works properly. |
One more point I didn't see before:
Code:
grep ${dt} $(ls -tr | tail -1) HTH Forrest |
Well the part that has me curious is this:
1. dt = month in letters, ie Jul for now 2. No other command, that i can see, will include the word "Jul" unless in a file name ... which from the OP was never used or retrieved. Just a thought |
I'm not getting what you are asking grail. The line:
dt=$(date "+%b") will assign dt the month in letters. The OP's line: ls -ltr | tail -1 | awk '{print "cat " $9}' | sh | grep $dt lists all file in long form sorted by time in reverse order then gets the last line with the tail command then gets only the 9th field and prints "cat FIELD9" with the awk command and pipes that string to sh so it will run "cat FIELD9" and send the entire file contents to grep for the month in letters (i.e. Jul for now). It is much more strait forward to just grep for the month in letters of the last item in the list sorted by time in reverse. HTH Forrest |
Hi Forrest
I follow your logic except for one small detail, at least on my system. I am going to break down the last command up until the end of the awk: Code:
ls -ltr |
Yeah, on my system there are also only 8 fields. But since the OP said script works properly, I just assumed the 9th field on their system was the filename since they were trying to cat it and that would mean it needed to be a file.
Forrest |
All times are GMT -5. The time now is 03:07 PM. |