Shell scripting Problems!
I'm looking for some help from anyone who knows shell scripting, I'm trying to do the following:
1-Accept a string form the terminal and use case to echo a suitable message if the string doesn't have at least 10 characters. and 2-Write a script that displays, in head-style, the last three lines of each file in the current directory, duly preceded by the filename. Thanks. |
Hey I got the answer to number one for you:
Code:
#!/bin/sh |
Take a look at the awk language.
|
Hey bud, here is number two:
Code:
#!/bin/sh |
I just remembered a simpler way to do question 2:
Code:
tail -3 file Enter Code:
tail --help |
PT,
If you noticed from herve's post he wanted the last three lines of EVERY file in the directory. I would assume that because he wants a script it is because he does not want to do tail -3 on every file (as there could be hundreds) Also I used tail -3 in my script above. Quote:
|
One of the lines on the script in post #4 can be shortened.
find -maxdepth 1 -type f | grep -v "rpm" | grep -v "tar.bz2" | grep -v "tar.gz" | grep -v "tgz" | grep -v "myscript" find -maxdepth 1 -type f | grep -v -e rpm -e tar.bz2 -e tar.gz -e tgz I will sometimes filter the output of 'locate' by using 'grep -v' and pressing the up arrow and adding more patterns to exclude with '-e pattern. It may be better to use the patterns -e ".rpm$" -e ".tar.bz2$" -e ".tar.gz$" -e ".tgz$" to avoid filtering out filenames that happen to have a matching pattern inside the filename. Also the pattern for hidden files would be "\..*" The backslash is needed to escape the period, because '.' alone represents any character. '.*' means zero or more of any character. Also, you could use: for file in `cat lastthree.tmp` do tail -3 $FILENAME >> threeout.tmp done |
Excellent modifications! That would definately make things look and feel cleaner! Thanks for the additional reply!
|
All times are GMT -5. The time now is 10:14 PM. |