The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help Required: Command to find IP address and command executed of a user loggedout Security 2 08-06-2008 09:12 PM
Sed-- command help required pssandeep UNIX for Dummies Questions & Answers 6 03-18-2008 10:43 AM
Help required using cut command mahalakshmi Shell Programming and Scripting 4 03-18-2008 06:36 AM
Help required on AWK command udiptya UNIX for Dummies Questions & Answers 13 01-22-2008 08:43 AM
Help required for cat command mahalakshmi Shell Programming and Scripting 7 11-23-2006 06:20 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-03-2008
dtidke dtidke is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 5
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 (permalink)  
Old 04-03-2008
Devesh5683 Devesh5683 is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 5
Try this..

set `wc -l file_name`
count=$1
echo $count
  #3 (permalink)  
Old 04-03-2008
javeed7 javeed7 is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 34
count=`wc -l test1`
use wc in back quotes. it works.ok
  #4 (permalink)  
Old 04-03-2008
dtidke dtidke is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 5
thanks guys its solve my problem
  #5 (permalink)  
Old 04-03-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink 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 (permalink)  
Old 04-03-2008
ShawnMilo ShawnMilo is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 252
Quote:
Originally Posted by joeyg View Post
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 (permalink)  
Old 06-05-2008
vnPrasanna vnPrasanna is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 2
Thumbs up 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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:51 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0