Operating System - HP-UX
1832337 Members
2409 Online
110041 Solutions
New Discussion

Re: Awk, Gawk How to make a list of files

 
SOLVED
Go to solution
Hanif Kazemi
Occasional Advisor

Awk, Gawk How to make a list of files

Hi,
I'd like to use Gawk/Awk to create a list of files that already are in a specific folder.

Then I'd like to add thses "file names" to an existing txt file.

Anyone expert on this? Please help
9 REPLIES 9
Patrick Wallek
Honored Contributor
Solution

Re: Awk, Gawk How to make a list of files

If you just want a list of files in a folder, you don't to get fancy with awk.

Just do:

# ls -1

This will create a 1 column list of files in whatever directory you are in. If you want to append that list to another file just do:

# ls -1 >> /dir/filename.txt

If this doesn't meet your requirements, please give more details about what exactly it is that you need.
Hanif Kazemi
Occasional Advisor

Re: Awk, Gawk How to make a list of files

Patrick,
Thanks very much for your incredibly fast reply.

This is what I need to do with Awk / GAWK:

From this directory like:
c:\helpfiles
1-Make a list of all .htm files
2-add this list (write the names of these files) to a specific .hhp file (like helprelesase.hhp)
Rodney Hills
Honored Contributor

Re: Awk, Gawk How to make a list of files

Since this is a HPUX forum, your question seems out of place.

A similar DOS command would be-

dir *.txt /b >>yourfile.hhp

HTH

-- Rod Hills
There be dragons...
TwoProc
Honored Contributor

Re: Awk, Gawk How to make a list of files

Hanif - it looks like this is a question for MSDOS users (C:\helpfiles is DOS format). If so, that goes in another forum.
We are the people our parents warned us about --Jimmy Buffett
Patrick Wallek
Honored Contributor

Re: Awk, Gawk How to make a list of files

Well, since this is an HP-UX forum, I assumed you were actually talking about doing this on a Unix machine. Silly me.

At the dos prompt in whatever directory you prefer:

dir /b *.htm >> c:\dir\yourfilename.hhp


You still don't need to get complicated with AWK to do this.
Hanif Kazemi
Occasional Advisor

Re: Awk, Gawk How to make a list of files

C:\helpfiles was just an example of where my .htm files might be.

That was a random name.

What I am asking is that what would be my Awk program which would this procedure:

1-go to a specific directory,
2-copy the list of all existing .htm files into a .hhp file


I really appreciate your help.


Patrick Wallek
Honored Contributor

Re: Awk, Gawk How to make a list of files

And my question is why do you insist on using awk to do this when there are easier ways to do it?
Hanif Kazemi
Occasional Advisor

Re: Awk, Gawk How to make a list of files

Ha ha

becuz I am an idiot.
I didn't even know this is a unix forum.

I actually can use anything, as long as it does the job. Somebody suggested Awk.

Could you let me know what you think is best for this purpose?

Thanks
Rodney Hills
Honored Contributor

Re: Awk, Gawk How to make a list of files

Awk is a tool and does not do file system type operations. Within awk you would call the "ls" or "dir" command to get the list and then you could do individual processing on each line.

awks strength comes in its ability to work with other utilities/tools, which in a DOS environment is not so easy.

If you really wanted to have awk do the process then...

awk '{"cd /dir ; ls -1" | getline; print $0 >>"your.hhp"}'

But this is not the cleanest way to use awk...

HTH

-- Rod Hills
There be dragons...