bash script for displaying a file one line at a time.
Hello,
I'm trying to implement a script that lists a file one line at a time as a part of an experiment (I want to more or less duplicate the behavior of the cat function using other bash commands). Why would I want to do this? I finished my first script a couple of days ago and I just want to try something a bit more different. So here is what I have now: Code:
line=1 |
This, of course, should have the same result as cat -n whatever_file.
All "cat -n" does is add a line number, so: Code:
nl whatever_file Code:
n=0; cat whatever_file|while read l; do ((n++)); echo "$n ${l}"; done Code:
let "line+=1" Code:
line=$[${line}+1] Code:
((line++)) Code:
line_to_display=$(head -$line < whatever_file | tail -1) Code:
((LINENO++)) function help() { echo "${FUNCNAME}: Bash scripting guides http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html http://www.tldp.org/LDP/Bash-Beginne...tml/index.html http://www.tldp.org/LDP/abs/html/" } |
Thanks once again unSpawn. I can only wish that some day I would be able to think out loud in the same way :). I will try your suggestions and then post the whole code for mycat function. I guess that for most of the things there will be a much simpler way.
P.S. I've gone through the Bash-Beginner-Guide and it's great reference. |
I'm through with some of stuff and I think I will be satisfied if this works because it incorporates the most common cat properties.
Code:
#!/bin/bash I do hope I am not asking too much and bothering you with my stuff. Kindest regards, Valentin |
Quote:
Code:
## -n case |
hello there. perhaps you're after something like this...
Code:
n=0 |
I've resolved my problems after re-installing Mandriva and now everything is fine and the script is working. Thaks for your suggestions and help, everyone. I will be posting the source when I come back home.
|
All times are GMT -5. The time now is 10:23 PM. |