Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Files list to a file..

Status
Not open for further replies.

kumariaru

IS-IT--Management
Mar 9, 2006
61
AU
Hi All,
I want a list of files sent to a file with word count.

Ex:
Srcdirectory:

File1.txt
File2.txt
File3.txt
File4.txt
File5.txt
.
..

I need a to build a file in this way
Filename,Count
File1.txt,2
File2.txt,78
File3.txt,100
File4.txt,90
File5.txt,78

And I want to overwrite this file everyday. I will be running this script everyday for same no. of files but with different record counts.

Thanks a lot..




 
Hi

Code:
wc -w Srcdirectory/* 2> /dev/null | sed 's/ *\([[:digit:]]\+\) \(.*\)/\2,\1/' > /output/file

[gray]# or[/gray]

wc -w * 2> /dev/null | awk '{print $2","$1}' > /output/file

Feherke.
 
Hi Feherke..
I tested with both the scripts, the scripts executed good but the output into the file is in this format:

/Srcdirectory/File1.txt,2
/Srcdirectory/File2.txt,78
/Srcdirectory/File3.txt,100
/Srcdirectory/File4.txt,90
/Srcdirectory/File5.txt,78

I used both the scripts to this. ..For both the scriptsI am getting same output..

Thanks a lot....
Kumari.

 
Try cding into the directory first, and don't specify the filespec with the full pathname.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top