Help Required regarding wc command


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
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  
Try this..

set `wc -l file_name`
count=$1
echo $count
# 3  
count=`wc -l test1`
use wc in back quotes. it works.ok
# 4  
thanks guys its solve my problem Smilie
# 5  
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  
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  
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 for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #966
Difficulty: Medium
In HTML5 the 'ol' element has a new attribute called 'inline'
True or False?

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. 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

3. Shell Programming and Scripting

Help required using cut command

Hi all, I have one text as '/home/psv/file/test.ksh'. In that I want to cut the text as '/home/psv/file/' . Let me know which command to use. Thanks Mahalakshmi.A (4 Replies)
Discussion started by: mahalakshmi
4 Replies

4. UNIX for Dummies Questions & Answers

Help required on AWK command

I have two questions: (Q1) I am using a loop and want to print a particular field of a table using the AWK command by accessing one row at a time by validating NR with the loop counter. I am using a command like this but it isn't working! count=1 NAWK -F"|" -v var=$count 'NR == var { printf... (13 Replies)
Discussion started by: udiptya
13 Replies

5. 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

6. UNIX for Advanced & Expert Users

Required unix command!!!

Hi, In a file I have data like... -rw-r----- 1 ftpuser users 1036695 Jul 6 14:59 ./APRIL 2007/Ujjain/My Disc (D)/9565DW07.04B -rw-r----- 1 ftpuser users 124080 Jul 6 14:59 ./APRIL 2007/Vadodara/vad_APRIL07/2082DW07.04B The above data is extracted using "find . -name... (12 Replies)
Discussion started by: ronald_brayan
12 Replies

7. UNIX for Dummies Questions & Answers

Help required for usermod command

Hi, I would need to modify my machine name : When i give "w" command, i am getting following message USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT krishnag pts/59 gunasekar 1:25pm 25:15 0.03s 0.03s -csh. My questions is, i need to change FROM (i.e... (1 Reply)
Discussion started by: gun
1 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. Shell Programming and Scripting

Help required in grep command

Hi all, I need some help in grep command in a ksh script. Actually, i need to list all files having the file name like "BORD*.DAT" but exclude the files (from the list) having name like "BORD*mgt*.DAT". For that i used the following command: ls | grep "BORD*.DAT" | grep -v "BORD*mgt*.DAT" ... (4 Replies)
Discussion started by: panzer
4 Replies

Featured Tech Videos