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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
change 43% to 43.5 nortypig Shell Programming and Scripting 2 08-20-2006 12:55 AM
IP change kuultak UNIX for Dummies Questions & Answers 2 07-13-2005 06:01 AM
UID Change mcateriny AIX 4 10-06-2003 09:02 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-14-2008
Registered User
 

Join Date: Apr 2008
Posts: 5
change wc -l

Hi,

I would like realize a script that it can change " wc -l" with "wc -l | sed 's/ //g'", but my problem is that i can have
a pipe ,a variable ( many variable different) or a file after wc -l ?how i could test this several case ?

wc -l | cut -d' ' -f1`
if [ `wc -l <$FILE` -ne 1 ]
wc -l ${F} | awk '{print $1 }'

Thank you for your help.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-14-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 2,707
I believe the function I posted earlier should work for all these cases.

Pb with space wc -l

Because I don't have the space problem, I made a slightly different wc function for testing here.

Code:
vnix$ type -all wc
wc is /usr/bin/wc
vnix$ wc () {
>   set -- `/usr/bin/wc "$@"`
>   echo $1
> }
vnix$ wc /etc/motd
8
vnix$ wc -l /etc/motd
8
vnix$ /usr/bin/wc /etc/motd
  8  50 338 /etc/motd
vnix$ wc -l </etc/motd | cut -d ' ' -f1
8
vnix$ if [ `wc -l </etc/motd` -eq 8 ] ; then echo foo ; fi
foo
vnix$ F=/etc/motd
vnix$ wc -l $F | awk '{ print $1 }'
8
Don't these cases work for you?
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:08 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0