Unix Assignment, need help!

I have been working on this for the past hour and I can not figure it out :frowning:

What command would you give to produce a listing of the names of all the text files in ~/UnixCourse or its subdirectories (possibly nested several layers deep) followed immediately by the first line of text within that file? E.g., to produce a listing looking like this:

/home/yourname/UnixCourse/foo.txt
When in the course of human development
/home/yourname/UnixCourse/Quotations/b...
Curiouser and curiouser!

find ~/UnixCourse/ -name *.txt > ars.data
file=ars.data

while read line
do
echo $line
cat $line | head -1
done < $file

this forum is not going to do your home work for you....
show us what you have so far and we may help.
don't expect us to give you a full work answer.

have a play with this:

ls -R ~/UnixCourse

and this:

head -1 blarg.txt

and find command can be good too.

and read man pages for above commands.

well we are currently working on redirection and pipelines, do I need to use a wildcard to search for the .txt documents?

find ~/UnixCourse/fileAsst/*.txt

like that find all the txt documents

a good start, now we need to do things with each line of output.

so we use a pipe looks like this ---> |

and we go into a loop a bit like this

while read VAR; do stuff; done

in your case you will be doing a head -1 of $VAR.

so.....

find stuff | while, read VAR;do head -1 VAR;done

and I know there are two bugs in that, I won't give out full answers for a homework question....
I am guide , not an answer book :slight_smile:

Oh I wasnt expecting a full answer

robsonde you have been a great help, I am going to try your advice out and Ill post an update of how far I get

also what exactly does $VAR do?

find ~/UnixCourse -name *.txt -print | head --lines=[-]1

hmm still not working, I am having trouble using the head line

Take a look at xargs

No Homework. Thread Closed.