Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Is there a unix command to combine files

Is there a unix command to combine files
Thread Tools
Fresh-Faced Recruit
Join Date: May 2005
Location: NJ
Status: Offline
Reply With Quote
Jul 26, 2005, 04:09 AM
 
Hi,

I have developed an Intranet Web Application for one of my clients and as part of my justification for the hours spent and total cost I want to get a total lines of code count. There is a master directory with a few sub directories containing other CFML (Cold Fusion Markup Language) files and image files. I was wondering if there was any UNIX command or simple method for essentially appending each of the files to a "MasterFile" which I can run and then just open that master file in Dreamweaver and get the line count. All together there are around 120 files so far, I can manually each one get the line count and throw that into a calculator or excel file, but I figured there has to be some form of easier unix command to do this.

Thanks,
ThePhoenix
     
Forum Regular
Join Date: May 2004
Status: Offline
Reply With Quote
Jul 26, 2005, 06:01 AM
 
Not a command, exactly. An operator will do...

cal 2005 > test.txt
cat test.txt
cal 2006 >> test.txt
cat test.txt

So you want to...
cat *.txt >> masterfile.txt

...making sure to change .txt to whatever is appropriate in your case. BTW, "wc -l" will count the lines for you.

-S
(Last edited by Sparkletron; Jul 26, 2005 at 06:08 AM. )
     
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status: Offline
Reply With Quote
Jul 27, 2005, 08:02 AM
 
Or to handle subdirectories:
find . -name '*.cfm' -exec cat \{\} >> master.txt \;

find finds files
. means to look in the current directory (and subdirectories)
-name '*.cfm' means find only files whose name ends in .cfm
-exec means run the following command on the file. The \{\} means 'put the filename here', and the \; means 'end of the command'
cat \{\} >> master.txt \;, as phoenix explained, copies each file onto the end of master.txt.

then
wc -l master.txt
gives you what you want.
     
Fresh-Faced Recruit
Join Date: Nov 2004
Location: Boston
Status: Offline
Reply With Quote
Jul 27, 2005, 03:30 PM
 
Easiest way to do a line count is:

wc -l `find . -name \*.cfm -print`

[Those are backwards apostrophes]

This gives a straight line count. I don't know cfm files, but for 'C' I prefer to count semicolons, so I use:

grep \; `find . -name \*.c -print` | wc -l
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 07:53 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2