You are not logged in.
Hello this is my first post!
I'm making a little script that reads a text file.
#/bin/bash
COUNTER=1
while read line
do
echo "$COUNTER"
COUNTER=`expr $COUNTER + 1`
done < mytextfile
I simply want to print the line number I'm currently reading but isn't there a more simple way to do this than what I have above?
Is the only way to do this is by using a temporary variable?
Thanks in advance
Last edited by tamikana (2010-04-06 15:22:52)
Offline
This sounds a lot like homework....
http://wiki.archlinux.org/index.php/For … e#Homework
Online
Well it's not like I don't know how to do what I want but I thought it'd be nice to know other ways by experienced people.
Offline
Thank you very much now I'm learning!
Offline
lol, brisbin!
awk '{array[NR]="read"}END{a=0;while(++a){if(a in array){print a}else{exit}}}' file
Offline
edit: double post
Last edited by Procyon (2010-04-06 17:47:42)
Offline