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
No space on /dev/hd 1/42 ibqti SCO 1 11-09-2007 01:53 PM
swap space / paging space aaronh AIX 2 05-19-2004 07:06 AM
how much space? pgas UNIX for Dummies Questions & Answers 1 04-06-2004 08:03 AM
pageing space vs swap space VeroL UNIX for Dummies Questions & Answers 1 01-22-2004 07:54 AM
More space grep UNIX for Dummies Questions & Answers 2 12-02-2002 11:08 AM

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

Join Date: Apr 2008
Posts: 5
Stumble this Post!
Pb with space wc -l

Hi,

i would work hp-ux script on an AIX, and i have a pb with wc -l command, on AIX this command made a space on output and hp not. And I would like use an alias or a function in order to remove this space on output without change code.


thanks for your help.

$ cat profile.ksh | wc -l
91
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-13-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Stumble this Post!
Echoing a variable or other expression without quoting it will remove any leading and trailing whitespace.

Code:
echo `wc -l <profile.ksh`
Usually echo `backticks` is mainly seen in really horrible newbie code, but the whitespace normalization is a useful and in this case desired side effect which makes this a legitimate use IMHO.

Note the use of redirection to avoid the Useless Use of Cat.

Are you sure about the AIX spacing issue, though? The situation where you usually see this is when you use wc -l file instead of wc -l <file (but then of course you get the file name also).
Reply With Quote
  #3 (permalink)  
Old 04-13-2008
Registered User
 

Join Date: Apr 2008
Posts: 5
Stumble this Post!
Hi, thanks you for your response.

Yes, i have this space on AIX, and not on HP-UX. I don't know why ?

right, with echoing , i don't have space , and with a sed too ( cat profile.ksh | wc -l | sed 's/ //g)

do you know how i can realise this change with an alias or function, in order to not change code ?? ( i have many shell scripts)

(wc -l profile.ksh | perl -ne 's/(.)/ord($1)/eg;print'
32323232323256523211211411110210510810146107115104)
32 are space.

Thanks in advance
Reply With Quote
  #4 (permalink)  
Old 04-13-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Stumble this Post!
Changing it with a function sounds perilous, but I suppose it could be done.

Code:
wc () {
  /usr/bin/wc "$@" | sed 's/ //g'
}
If your wc is not in /usr/bin, you will need to modify this. If it's at different paths on AIX and on HP-UX, you will have to parametrize that, too. Maybe something like this:

Code:
case `uname -s` in
  AIX) wc=/tru/blu/wc;;
  HP-UX) wc=/ick/opt/we/are/weird;;
esac

wc () {
  $wc "$@" | sed 's/ //g'
}
I don't have ready access to AIX or HP-UX systems so I can only guess what they print for "uname -s".
Reply With Quote
  #5 (permalink)  
Old 04-13-2008
Registered User
 

Join Date: Apr 2008
Posts: 5
Stumble this Post!
Era, I thank you for your helps.

it 's ok
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:48 AM.


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