Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple question

Status
Not open for further replies.

hokky

Technical User
Nov 9, 2006
170
AU
Hi guys
here's my code

Code:
NUMBER=`ls Run_*.flag | wc -l`

echo "BATCH_$NUMBER"

let's say the flag file is 7
The result is BATCH_ 7

I want the result is BATCH_7

I have the way like this but I don't like it
NUMBER=`ls Run_*.flag | wc -l | awk '{print $1}'`

I was just wondering using eval or something which is more proper...
Thanks guys
 
Well , I'm not sure what's not to like.
NUMBER=`ls Run_*.flag | wc -l | awk '{print $1}'`


But if you are trying to get rid of the space between BATCH_ & 7.

The wc -l command puts the space in your answer. It's possible that washing the string back thorugh the shell interpreter via "eval" might remove the space, But I think using sed or awk (like you did aabove) is far more straight forward.

JRjr
[morning]
 
Something like this?

Code:
NUMBER=`ls Run_*.flag | wc -l`
(( NUMBER=NUMBER+0 ))

echo "BATCH_$NUMBER"


HTH,

p5wizard
 
Another way:
Code:
NUMBER=`ls Run_*.flag | awk 'END{print NR}'`
echo "BATCH_$NUMBER"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Another way in Korn Shell...
Code:
typeset -i NUMBER=$(ls Run_*.flag | wc -l)

echo "BATCH_$NUMBER"
The "[tt]typeset -i[/tt]" makes the variable an Integer which can have no spaces.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top