Help Required regarding wc command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help Required regarding wc command
# 1  
Old 04-03-2008
Help Required regarding wc command

Hi guys,

I want to find the number of records in a particular file and store that value in any other variable. I am trying this below command but it is not working and giving me an error "Uninary Operator Expected".

say I have taken a variable name 'count' in which I have to store the no. of records in a file.

count= wc -l <file name>

can u guys pls help me out...how i can store a no. of records in a variable
# 2  
Old 04-03-2008
Try this..

set `wc -l file_name`
count=$1
echo $count
# 3  
Old 04-03-2008
count=`wc -l test1`
use wc in back quotes. it works.ok
# 4  
Old 04-03-2008
thanks guys its solve my problem Smilie
# 5  
Old 04-03-2008
Hammer & Screwdriver Another approach without the tics

Because sometimes they can confuse...

>count=$(wc -l file_name)

I like this because whatever I would normally type at the command prompt I simply put inside the parentheses.
# 6  
Old 04-03-2008
Quote:
Originally Posted by joeyg
Because sometimes they can confuse...

>count=$(wc -l file_name)

I like this because whatever I would normally type at the command prompt I simply put inside the parentheses.
I also prefer this approach. For reference, surrounding the statement in parenthesis actually creates a sub-shell (another process). Putting the $ in front of it lets you use the result as a value.
# 7  
Old 06-05-2008
MySQL How to store the count of occurences in a file

Hi,

I want to store the count for a number of occurrences of a string (Ex: Sample.test.test1) in a variable from a file.

For the above string format, please tell me how to find it.

Also, I have one more question.


I want to count the number of occurrences of a sentence in file and this count needs to be stored in a variable.

Anyone, please help in solving the above two issues ASAP.

Regards,
Prasanna
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Required Command in awk command

Hi Firends, I wanted to extract the first record of the file which starst with character say "X". And I tried an awk command which works when i try to execute it individually: awk 'substr($1,1,1)=="X"' inputfile.txt But when I use the same command in my script for which I am passing the... (2 Replies)
Discussion started by: Ajay Venkatesan
2 Replies

2. UNIX for Dummies Questions & Answers

Help required with move command

Hi I need to move the first file in a folder to an another folder but am facing issues with the below cmd. CAN someone correct me Ex : Folder :data/cat/tst ad2 ad4 ad5 ad6 output req: data/cat/man ad2 Command Used : ls -lt ad*|head -1|mv/data/cat/man (3 Replies)
Discussion started by: akshay01987
3 Replies

3. Shell Programming and Scripting

Help required on scripting the rm -f command

When i execute rm -f $1 via a script file named rmf, it is not deleting all the files, say starting with "sec". i have execute rmf for many times to remove all the occurrences... $rmf sec* - this should delete all files starting with sec, but not. The rm -f sec* is working fine. kindly help... (3 Replies)
Discussion started by: frozensmilz
3 Replies

4. Cybersecurity

Help Required: Command to find IP address and command executed of a user

Hi, I am trying to write a script which would figure out who has run which command and their IP. As i dont have any clue as to which commands would do this job, i request some gurus to help me on this. Thanks Vishwas (2 Replies)
Discussion started by: loggedout
2 Replies

5. Solaris

required command to know the port no.

Can anybody have the command to know the port no using unix command for the weblogic server application. (1 Reply)
Discussion started by: Amit_kolurwar
1 Replies

6. UNIX for Dummies Questions & Answers

Sed-- command help required

Hi Gurus, I have a small requirement. Let suppose i have a file test.txt test.txt contains Dispatched date = '2008-04-08' Name = 'Logers' Now i want to add one more line to it as Number of Responses = "$a" $a will be chnaging dynamically which i had grepped it in the script. Now i... (6 Replies)
Discussion started by: pssandeep
6 Replies

7. UNIX for Dummies Questions & Answers

Required help in chmod command

I have files inside the some directories. The no. of files in each directory will vary from 1 to 500K. I need to change the permissions of all the files to 400 mode. When the files are large in numbers...the command $chmod 400 * fails saying "ksh: /bin/chmod: arg list too long" so I have... (5 Replies)
Discussion started by: lokachari
5 Replies

8. Shell Programming and Scripting

Help required for cat command

Hi, I had written the following script to find the list of files with *.ksh in a directory. and store it in a temp file. I want to loop through the file temp and list the contents. I had used cat temp. But its giving Cat and temp as the output. Do help me out. Thanks find .... (7 Replies)
Discussion started by: mahalakshmi
7 Replies

9. UNIX for Dummies Questions & Answers

Help Required in Unix Command

Hi All, Can anyone please help me in unix command Query: ==== File contains data along with date and time stamp like, .. Date: 08:23:2005 01:00:00 method: xyz init variables Date 08:23:2005 01:00:01 method: xyz finished init variable .... (2 Replies)
Discussion started by: thaduka
2 Replies

10. Solaris

unix command required.

I need to get a few details from the command line. I need to get the kilobytes per second that my server is transfering to another or has available and I need to test the connection to make sure that its a sound connection. I also need to keep track of the response time. I have been playing... (1 Reply)
Discussion started by: nowayin
1 Replies
Login or Register to Ask a Question