1846622 Members
1682 Online
110256 Solutions
New Discussion

Script help

 
Mike_305
Super Advisor

Script help

Hi,

I need to script this process and not sure how to do it. Currently, I use command line to do the things. If I can use “awk” or “sed” to filter the dates out from the “xyz.master” file and use a simple script to create the file that will be great.

cat xyz.master | grep -i "2006/10/07-" > xyz.list
cat xyz.master | grep -i "2006/10/08-" >> xyz.list
cat xyz.master | grep -i "2006/10/09-" >> xyz.list

then we take the final file and sort using the following command and fileter out the stuff we don't need.

sort -k 4,4 -k 5,5 -k 3,3 xyz.list > xyz.sorted.list

I have try using simple loop but that did not work

while true

do

Command to execute

done

exit

Thanks I appreciate your help.

Mike

If there is problem then don't think as problem, think as opportunity.
3 REPLIES 3
Bill Hassell
Honored Contributor

Re: Script help

Well, I think you've left out some important details, but to accomplish exactly what have described, it takes just one line:

grep -e "2006/10/07-" -e "2006/10/08-" -e "2006/10/09-" xyz.master | sort -k 4,4 -k 5,5 -k 3,3 > xyz.sorted.list

I'm not sure why you are looking at a loop.


Bill Hassell, sysadmin
Peter Godron
Honored Contributor

Re: Script help

Mike,
you can make your search more flexible, by using the -f option of grep.
Create a file "sdates" with your search dates:
2006/10/07-
2006/10/08-
2006/10/09-
Then use Bills solution:
grep -f sdates xyz.master | sort -k 4,4 -k 5,5 -k 3,3 > xyz.sorted.list

To add todays date to sdates:
date -u "+%Y/%m/%d-" >> sdates

In your original grep you also did not need the -i as you were searching for non-alphabetics.
Mike_305
Super Advisor

Re: Script help

Thanks guys, appreciate your help.

Mike
If there is problem then don't think as problem, think as opportunity.