HELP! writing simple shell script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers HELP! writing simple shell script
# 1  
Old 03-11-2008
HELP! writing simple shell script

how would i write a shell script to show the number of lines in which int variable appears in a c++ program.
# 2  
Old 03-11-2008
weeelll

Code:
grep -cw int infile

will tell you how many lines contain at least one int

probably better is something like:

Code:
 tr -cs "[:alpha:]" "[\n*]" < infile | grep -cw int

i.e. create list of words, one per line, then do the count...
# 3  
Old 03-11-2008
Hammer & Screwdriver

thanks

but how would i do this using cut or awk methods is it possbile and having a output similar to this

x, number of apperances =
y, number of apperances =
# 4  
Old 03-11-2008
Quote:
Originally Posted by deadleg
thanks

but how would i do this using cut or awk methods is it possbile and having a output similar to this

x, number of apperances =
y, number of apperances =
I'm not sure if this is what you want, but here's one possible method to get the counts for several different words within a file:

Code:
for W in int float char; do echo $W; egrep "\b$W\b" import.php | wc -l; done

(add a -i after the egrep for case-insensitivity)

ShawnMilo
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Need help in writing shell script

Dear Team, Below is the list of steps i need to perform manually as of now and completely new to shell scripting, could you help in writing a shell script to perform the below procedure? 1. Log in to primary DNS server 2. Check /etc/named.conf if zone is already created (grep –i... (2 Replies)
Discussion started by: VKIRUPHAKARAN
2 Replies

2. UNIX for Dummies Questions & Answers

Need help writing shell script!

Hi, I'm very new to this, so bear with me please. I want to write a sh script (or if there's a better format please let me know) that allows me to, when I run it, print the date to a file (1.out) take 2 arguments (files a.fa and b.fa), run them with another program, outputting to 2.out, and then... (4 Replies)
Discussion started by: ShiGua
4 Replies

3. Shell Programming and Scripting

Need help writing shell script!

Hi, I'm very new to this, so bear with me please. I want to write a sh script (or if there's a better format please let me know) that allows me to, when I run it, print the date to a file (1.out) take 2 arguments (files a.fa and b.fa), run them with another program, outputting to 2.out, and then... (2 Replies)
Discussion started by: ShiGua
2 Replies

4. Shell Programming and Scripting

writing a simple script to get total number of cpus/cores in server

Hi, I am very new to scripting and I wanted to write a unix shell script which can give me, 1)number of cpu's in a box 2)number of cores per cpu 3)total number of cores in abox (ie multiplying 1&2) I am also trying to figure out how to check if hyper-threading is enabled in the... (8 Replies)
Discussion started by: steven12
8 Replies

5. Shell Programming and Scripting

Writing a shell script

Hi I have two files a.log and b.log . i need to append a.log and b.log so that at the end of first line in a.log i need the append the data of first line from b.log and end of the second line in a.log i need to append the data of second line from b.log and so on up to the end of the file can... (3 Replies)
Discussion started by: lalu
3 Replies

6. Shell Programming and Scripting

problem writing a simple c shell script

#!/bin/csh echo hello world this is what i got in a text file called ss1. i type "chmod 755 ss1.txt" to make it executable. then when i type ss1 or ss1.txt it says "ss1 command not found" what am i doing wrong? (19 Replies)
Discussion started by: pantelis
19 Replies

7. Shell Programming and Scripting

Help with writing simple bash script

I want to write a bash script to: 1. Send an email from localhost to an external gmail account. (gmail then automatically forwards the message back to a pop account on the same server. 2. Script waits 3 minutes then checks to see if the email arrived, and if not, it sends an email to... (9 Replies)
Discussion started by: sallyanne
9 Replies

8. Shell Programming and Scripting

Need help in writing the shell script

Can anyone please help me in writing a shell script that would check if a particular user(xyz) has logged in, and if yes, the audit daemon needs to be started. When the user logs off the dameon needs to shutdown , and the report needs to be e-mailed to a set of users. (12 Replies)
Discussion started by: ggayathri
12 Replies

9. AIX

Difference between writing Unix Shell script and AIX Shell Scripts

Hi, Please give me the detailed Differences between writing Unix Shell script and AIX Shell Scripts. Thanks in advance..... (0 Replies)
Discussion started by: haroonec
0 Replies

10. UNIX for Dummies Questions & Answers

Need help writing simple script

I'm trying to write a simple unix script that will delete files after 30 days of being created. I've never done this before but conceptually it sounds easy. Here is what I'm trying to do: Get System Date Get File Date If (sysdate-filedate>30days) rm file All of these files are contained... (1 Reply)
Discussion started by: tamdoankc
1 Replies
Login or Register to Ask a Question