Quote:
Originally Posted by shadownet
Hi, I am a bit newbie to shell scripting. I want to write a script which takes two inputs 1. Name of the file, 2. No of lines to grep. After taking this two inputs the script should grep no of lines (input 2) from the file (input 1) and put the results into a new file. The new filename can be <filename>.<current date>. So for example if i run the script:
# ./grepscript 100linesoflog.txt 10
This should create a new file called 100lineoflog.txt.20130524 which contains last 10 lines from 100linesoflog.txt
Also if 100lineoflog.txt.20130524 already existed then the new file should be created as 100lineoflog.txt.20130524-1 and if 100lineoflog.txt.20130524-1 exists then script should create 100lineoflog.txt.20130524-2 and so on.
Can someone plz help me write this script. Also since i want to learn please provide explanation on the contents of the script if possible.
|
Please spell out your words. And as was said, we will be glad to help you, but we will not write it
FOR YOU. Also, saying that you want to learn...so we should explain every step to you...is pretty transparent. That probably means your teacher wants you to explain/show your work.
If you really want to learn, then post what you've written/tried, and where you're stuck, and you'll gladly get help.