Interested in partial command output.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Interested in partial command output.
# 1  
Old 12-15-2004
Hammer & Screwdriver Interested in partial command output.

Command output is given to the console. As in the following case -

wc -l filename
produces following output
nn filename

From this, I am only interested with nn(rowcount). Cant we simply extract it thr console?

I also tried with null device, I know as - /dev/null

wc -l filename > /dev/null | cut -d " " -f 1 /dev/null

This also didnt help me.

Will I have to use temporary file, in order to retrieve only rowcount?
# 2  
Old 12-15-2004
The easiest way is to pipe it through awk
Code:
wc -l file | awk '{print $1}'

You can omit the filename by supplying the file as STDIN, e.g.
Code:
$ wc -l < file

but you'll still get leading whitespace. So the awk solution is easiest.

EDIT: Looking at this, it'd be less expensive to just do the whole thing with awk...
Code:
awk '{c++} END{print c}' file

Cheers
ZB

Last edited by zazzybob; 12-15-2004 at 11:07 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert title as output of command to appended file if no output from command

I am using UNIX to create a script on our system. I have setup my commands to append their output to an outage file. However, some of the commands return no output and so I would like something to take their place. What I need The following command is placed at the prompt: TICLI... (4 Replies)
Discussion started by: jbrass
4 Replies

2. Shell Programming and Scripting

AWK - Print partial line/partial field

Hello, this is probably a simple request but I've been toying with it for a while. I have a large list of devices and commands that were run with a script, now I have lines such as: a-router-hostname-C#show ver I want to print everything up to (and excluding) the # and everything after it... (3 Replies)
Discussion started by: ippy98
3 Replies

3. What is on Your Mind?

In which sport are you interested?

I am swimmer and also gym is here . What sport do you practice ? (8 Replies)
Discussion started by: solaris_user
8 Replies

4. UNIX for Dummies Questions & Answers

Command display output on console and simultaneously save the command and its output

Hi folks, Please advise which command/command line shall I run; 1) to display the command and its output on console 2) simultaneous to save the command and its output on a file I tried tee command as follows; $ ps aux | grep mysql | tee /path/to/output.txt It displayed the... (7 Replies)
Discussion started by: satimis
7 Replies

5. Shell Programming and Scripting

Interested in getting new projects

Hi , I am interested in getting some new projects on shell scripting . Can some one suggest me some bidding site where I can get the projects. Regards (0 Replies)
Discussion started by: himvat
0 Replies

6. UNIX for Dummies Questions & Answers

Searching partial columns and returning maximum as output

Hello, I am just getting starting with awk and wondering if anyone could help with the following problem. I have a large file of data, 50,000 rows x 6 columns. I would like to search in blocks of 500 rows for a maximum value in a specific column and compile an output file that prints the... (0 Replies)
Discussion started by: xb_analysis
0 Replies

7. UNIX for Dummies Questions & Answers

Interested, but lost.

Alright, so I'm interested in using Unix, but I have a couple of pretty basic questions: 1) What's the relationship between Linux and Unix? Are they one and the same, or completely different? 2) Can you use Unix on a laptop? and 3) Where can you get Unix? Thanks for listening. (9 Replies)
Discussion started by: Ned
9 Replies

8. UNIX for Dummies Questions & Answers

Extremely Interested

As i was reading an article on being a "HACKERS" which was 30 minutes ago thinking that HACKING was the same as CRACKING, after the reading i discovered their difference, a hacker builds the internet while crackers just cracks and annoy like phreaking and breaking into people's computer. That... (5 Replies)
Discussion started by: Punk18
5 Replies
Login or Register to Ask a Question