unix command - bash shell


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers unix command - bash shell
# 1  
Old 01-28-2009
Tools unix command - bash shell

Hey all,

I need to know how many lines of C code are in a source bundle. I have extracted the bundle and hence there is a big directory tree with C files everywhere.

So far I have something like:

find . -name "*.c" | grep \ ./*/*/*/*/*/*

obviously wrong, if someone could help me out that would be great thanks!

~ Dan
# 2  
Old 01-28-2009
Assuming you just want line count:

find . -name '*.c' | xargs wc -l | tail -1
or

find . -name '*.c' | xargs awk ' END { print NR } '
# 3  
Old 01-28-2009
Thanks mate, although I ended up doing it with this before you replied:

find . -name "*.c" | cat | xargs grep -c ".*" | awk -F: '{ s+=$2 } END {print "TOTAL: ", s}'

Which I stumbled on by fluke, I look forward to using your simpler version, thanks.

~ Dan
# 4  
Old 01-29-2009
Just in case anyone else needs this post I came up with this as my final solution:

find . -name '*.cpp' | xargs wc -l | grep total | awk -f: '{ s+=$1 } END {print "TOTAL: ", s}'

The solution in the previous post only prints the last total. However on Solaris it prints the "Total" for each sub directory as well. This is handy if you are recursing a deep directory tree.

Cheers,

~ Dan
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX Korn Shell to Linux Bash

Migrating Unix batch jobs (Korn Shell) running in HP-UX server to Linux environment. Hi All Please help me to understand the easiest way to migrate Kernel Shell scripts to Linux Bash. Also let me know 1. Any automated scripts or tools available for this. 2. Challenges and issues... (5 Replies)
Discussion started by: cpremesh
5 Replies

2. UNIX for Dummies Questions & Answers

Which of the following command displays your login shell in bash shell?

Options:: A)$shell B)echo $ bash C)echo $ O D)$ O (1 Reply)
Discussion started by: raghugowda
1 Replies

3. Shell Programming and Scripting

Help with Unix bash shell script login

Hi, I am a complete Unix novice and need some help with creating a login shell script. I have created a file with user details i.e. PIN, name etc and require help in recalling the specified details from the file and being prompted for a password on login. Any help would be very much appreciated.... (0 Replies)
Discussion started by: tdsrogers
0 Replies

4. Shell Programming and Scripting

Creating a command on a BASH shell

Hi all. Suppose I have the following function in an executable file named "HOLA": ------------------------ function hola { echo "Hola ${@}."; } ------------------------ In addition, suppose that I want to execute the file so I can input my name next to ./HOLA. I mean,... (4 Replies)
Discussion started by: hresquivelo
4 Replies

5. Programming

Unix shell with history features like in bash

hii to all i am developing a simple unix shell in c i want to add history feature in that how could i do that plz help if there is any tutorial or website plz put it here history feature should be like that in bash, when press up key show the previous command typed in console plz be... (1 Reply)
Discussion started by: vipin_jss
1 Replies

6. UNIX for Dummies Questions & Answers

Help with date command in bash shell programming

Doubt #1 I have a program that I want the user to input date. When the user inputs the date, is it able to format it to system date dd-mm-yyy and then echo the value into a text file? Doubt#2 If the above is not going to work, I tried to have the system date appear in the user input field and... (6 Replies)
Discussion started by: frossie
6 Replies

7. Shell Programming and Scripting

bash variable - unix command

I want to just run this command from a bash script and put it in variable. date '+%M' gives the minutes in solaris. (2 Replies)
Discussion started by: photon
2 Replies

8. UNIX for Dummies Questions & Answers

more command does not work in bash shell

is there a different command to display contents of a file on the output in bash shell? i tried more and it does not work. (7 Replies)
Discussion started by: npatwardhan
7 Replies

9. UNIX for Advanced & Expert Users

Bash/Unix Command Errors

Hi all, I have major errors on entering the shell. On login I get: -bash: dircolors: command not found -bash: tr: command not found -bash: fgrep: command not found -bash: grep: command not found -bash: grep: command not found -bash: id: command not found -bash: # root@host # pwd /bin... (0 Replies)
Discussion started by: wcmmlynn
0 Replies

10. Shell Programming and Scripting

Using variable with cp command in bash shell

Hi, I am trying to write script to copy some files(/ppscdr/cdrp2p/temp/) from one directory to another directory using shell script. see the script below, #!/bin/sh -f dir_name=20061105 mkdir ${dir_name} cd /ppscdr/cdrp2p/temp pwd cp p2p${dir_name}*.*... (4 Replies)
Discussion started by: maheshsri
4 Replies
Login or Register to Ask a Question