How many lines are in a command.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How many lines are in a command.
# 1  
Old 05-20-2009
How many lines are in a command.

Hey I am learning shell-script as a beginner. I wanted to know how I can print out the number of lines in a command, is that possible first? I know of the command wc but it only works with file? What I want to do is, say I type in man ps and I get sooooo many lines. So I wanted to know if it is possible that I ask the programme to tell me the number of lines in that command or even go further and look for lines that contain the letters pr, for example.
# 2  
Old 05-20-2009
You can use
Code:
ps -ef | grep pr

or to just know the count of lines that match the string "pr" you can use:

Code:
ps -ef | grep -c pr

Padow
# 3  
Old 05-20-2009
Thank you Pad. Just to understand more. What if I want to add an option to the command? Say instead of ps, I want to type ps -e.
# 4  
Old 05-20-2009
Oh OK. I just tested it, seems you just add the option. Thank you!
# 5  
Old 05-21-2009
Hey sorry, it is not working. I mean if I want to know number of lines in a command, I use? I tried to use ps -ef | grep without the pr because I wanted to know only the number of lines in the command ps but it does not work. My question is, how can I know the number of lines in a command and also specifically number of certain pair of letters say PS only in a certain command?
# 6  
Old 05-21-2009
the "-c" option with grep will provide a count of the lines that match the search criteria.

Maybe I don't understand your question. I was assuming that "number of lines in a command" meant "number of lines of output resulting from an executed command".

Last edited by Padow; 05-21-2009 at 04:37 PM.. Reason: changed with to will
Padow
# 7  
Old 05-21-2009
OK, I will explain. There are numerous commands as you know and with the man page you can know about this command. So let us say, I type in man ls for example, or with an option man ls -l, and I get info about this command. Now what I want to do is this: I want to ask the program to tell me how many lines will the man page display about this specific command, in our example ls or with option ls -l. And then again ask about how many specific pair of letters come up in the man pages of this command. So using our example again (ls), I want to ask the programme how many of the letters lm appear in each line of the man pages of this command, for example. To sum up.

I want to know:
1. How many lines about a certain command appear in the man pages when I type man command or man comman -option.
2. How many pair of words appear in each line. So for example to know how many lm appear in each lien of this command in the man pages.

Hope it is a bit clear now. Sorry, if I didn't make it clear before!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

What does this command do? and how to decode all other lines

Hello, I have an encoded file and I wish to see what is written inside. The first line is given below: eval "$(dd if=$0 bs=1 skip=69 2>/dev/null|gpg -d 2>/dev/null)"; exit PS: When I google above code, it says that command is use for encryption... Following lines include many strange... (2 Replies)
Discussion started by: baris35
2 Replies

2. UNIX for Advanced & Expert Users

Need command for grepping pattern lines with subsequent lines

Hi, I have a requirement like, I have a list of pattens in a file say pattern.txt, PHC111 PHC113 and in another file called master.lst i have entries like, PHC111 a b PHC112 a PHC113 b c PHC114 d e (5 Replies)
Discussion started by: rbalaj16
5 Replies

3. Shell Programming and Scripting

Command on multiple lines

I am writing a script and my command is long so it goes down to the next line, but it does not run properly, the pipe is missing the wc -l. how do i fix this problem. find ${ARCHIVE}/${dir} -type f -name "${TEMP2}*" | awk -F/ '{print $NF}' | wc -l (8 Replies)
Discussion started by: football12345
8 Replies

4. Shell Programming and Scripting

bash logging al $() command lines

I have been doing a lot more bash on LINUX RedHat and Ubuntu lately, and one thing keeps cropping up intermittently. If I do a $( some-commands ) Command Substitution, the some-commands are logged onto my screen each time they are evaluated. Did I turn on some odd option? It seems to happen just... (13 Replies)
Discussion started by: DGPickett
13 Replies

5. Shell Programming and Scripting

getting two lines by using grep command

i hav a text file(abc.txt) in which it have 2 lines as shown Number of agencies didnt send the file= 0 sum of reject files= 0 ###### to get one line from the text file ... i use grep command grep 'Number of agencies didnt send the file= 0' abc.txt ... (7 Replies)
Discussion started by: nani1984
7 Replies

6. Shell Programming and Scripting

Cat Command and Blank Lines

Hi All, I was testing for blank lines and I want to use the cat command only for groupline in `cat /home/test/group` do if then echo "blank found" fi done I want to check if the current line read is a blank line. I have tested with $groupline="\n" ,... (11 Replies)
Discussion started by: datkan
11 Replies

7. Shell Programming and Scripting

Repeat same command on multiple lines

HI I have a text file named docs with 100 filenames with full directory path one by one. I want to perform an action on all of them, the action i want to do this chown bin:bin <filename>. The <filename> should be each line in the docs text file. Please give the code. Somebody told to use for... (2 Replies)
Discussion started by: PrasannaKS
2 Replies

8. Shell Programming and Scripting

awk/sed Command : Parse parameter file / send the lines to the ksh export command

Sorry for the duplicate thread this one is similar to the one in https://www.unix.com/shell-programming-scripting/88132-awk-sed-script-read-values-parameter-files.html#post302255121 Since there were no responses on the parent thread since it got resolved partially i thought to open the new... (4 Replies)
Discussion started by: rajan_san
4 Replies

9. UNIX for Dummies Questions & Answers

list last few lines command

Hi If my ls -l results in 1000 lines and i just want to see the last few lines in the list what arguments do i pass eg lets say i want to see only the last 5 lines of 'ls -l' result (2 Replies)
Discussion started by: zomboo
2 Replies

10. Shell Programming and Scripting

Re: Long command lines

Hello, AIM: Need to test for the presence of some files (*.F) in a certain directory. having a problem with this line is ksh: if test `ls $SOMEDIR/dir/*.F \ 2>/dev/null|wc -w` -eq 0 Basically testing for the presence of *.F files in the specified directory. If the return... (4 Replies)
Discussion started by: enoch
4 Replies
Login or Register to Ask a Question