LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-12-2010, 02:55 AM   #1
laki47
Member
 
Registered: Feb 2009
Posts: 33

Rep: Reputation: 15
Leading blanks - problem


Can you please help me with the following:

# num_count=`ls /tmp/countdir |wc -l`
# echo "Number of files in /tmp/countdir is ($num_count)"
Number of files in /tmp/countdir is ( 5)

Why do I have 7 leading blanks before number 5?

How could I avoid that?

Thanks!
 
Old 05-12-2010, 03:01 AM   #2
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,300

Rep: Reputation: 102Reputation: 102
Lightbulb

Quote:
Originally Posted by laki47 View Post
Can you please help me with the following:

# num_count=`ls /tmp/countdir |wc -l`
# echo "Number of files in /tmp/countdir is ($num_count)"
Number of files in /tmp/countdir is ( 5)

Why do I have 7 leading blanks before number 5?

How could I avoid that?

Thanks!
Use this code

Code:
num_count=`ls /tmp/countdir |wc -l`
num_count1=`echo $num_count | sed -e 's/^[ \t]*//'`
echo "Number of files in /tmp/countdir is ($num_count1)"
 
Old 05-12-2010, 03:04 AM   #3
laki47
Member
 
Registered: Feb 2009
Posts: 33

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by laki47 View Post
Can you please help me with the following:

# num_count=`ls /tmp/countdir |wc -l`
# echo "Number of files in /tmp/countdir is ($num_count)"
Number of files in /tmp/countdir is ( 5)

Why do I have 7 leading blanks before number 5?

How could I avoid that?

Thanks!
Can I use (KORN SHELL):

typeset -i num_count
...

Last edited by laki47; 05-12-2010 at 03:06 AM.
 
Old 05-12-2010, 04:08 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by laki47 View Post
Why do I have 7 leading blanks before number 5?

How could I avoid that?
Use my system! I could not reproduce the problem:
Code:
c@CW8:~$ num_count=`ls /tmp | wc -l`
c@CW8:~$ echo "Number of files in /tmp is ($num_count)"
Number of files in /tmp is (4)
c@CW8:~$ ls /tmp | wc -l
4
What is the output of ls /tmp/countdir |wc -l on your system?

Which shell are you using? If ksh, how have you declared num_count or is it implicitly declared as an ordinary variable?

EDIT: in ksh, to print the attributes of variable num_count try typeset -p | grep num_count (not tested; no ksh to test on).

Last edited by catkin; 05-12-2010 at 04:20 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
linux (gnu) sort leading blanks alex_martin62 Linux - Newbie 3 06-21-2009 05:51 PM
tar problem - Removing leading / from hard link targets rajeshkahara Linux - Software 2 01-05-2006 02:33 PM
Problem with tar - Removing leading `/' from hard link targets rajeshkahara Linux - Software 1 01-03-2006 06:23 PM
Problem with tar - Removing leading / from hard link targets rajeshkahara Linux - Software 4 01-03-2006 05:22 AM
mistake leading to a problem with internet duffmckagan SUSE / openSUSE 5 04-14-2005 04:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration