Display from a variable using echo.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Display from a variable using echo.
# 1  
Old 06-12-2003
Display from a variable using echo.

I have a variable that is outputting a lot of space.

here has been 45 lines returned ...

how can I remove the spaces between the "been and the 45"
CODE:

fil_len=`wc -l < coshb.txt`
if [ ${fil_len} -gt 21 ]; then
cat coshb.txt | more
echo " "
echo "There has been ${fil_len} lines returned ..."

I am using a ksh in Solaris.

Thank in advance
Smilie
# 2  
Old 06-12-2003
Go to a command prompt and actually type in the command wc -l coshb.txt and you'll understand why..

You could substitute this:

fil_len=`wc -l < coshb.txt | awk '{print $1}'`
# 3  
Old 06-12-2003
One way...
echo "There has been" ${fil_len} "lines returned ..."
# 4  
Old 06-12-2003
Cool!!!!

Now can you explain what the was wrong with my previous line and how the new line is doing what I actually want?????

fil_len=`wc -l < coshb.txt | awk '{print $1}'`


Thanks for the quick response.

Smilie
# 5  
Old 06-12-2003
Wow.. mine looks at the output of the command and, using spaces as a field delimiter, prints the first (and in this case, only) field, the number of lines in your file. But it calls the awk utility.. really I think Perderabo's is faster - it uses the fact that if you echo a variable without enclosing it in quotes, all spaces are stripped from the variable before being output to the screen..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

display echo only once

lets say I am printing something out echo "Please enter a valid username" and its being printed out 5 times, is there any way I can limit to only being displayed ONCE. I tried echo -n but that just makes everything fit on one line. Right now it keeps saying Please enter a valid... (5 Replies)
Discussion started by: subway69
5 Replies

2. Shell Programming and Scripting

echo the NAME of the variable

#!/bin/bash varA="AAA1" varB="BBB2" varC="CCC3" for proccx in $varA $varB $varC do echo "the current name is ????? , the value is $proccx" echo " " done #end of script I want the output to look something like this: the current name is varA, the value is AAA1 the current name is... (5 Replies)
Discussion started by: ajp7701
5 Replies

3. Homework & Coursework Questions

Using ls or echo to display a specific output

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: What single command line would you enter to get the following output? 8140 drwxr-xr-x 9 root bin 18 Jan 20... (6 Replies)
Discussion started by: dasboot
6 Replies

4. UNIX for Dummies Questions & Answers

How to assign echo in variable

I've testing the following code: echo test.txt | cut -d . -f1and get the output "text" So why can't i assign the command to a variable? VAR='"echo test.txt | cut -d . -f1"' echo $VAR (5 Replies)
Discussion started by: jl487
5 Replies

5. Shell Programming and Scripting

Display and write in file in one echo command

Hi All, I want to display content on command promt and also write in file. For that iI ahve to write two sentence echo "XXXXXXX" echo "XXXXXXXX" >> 1.txt Is there any way to write in one echo statement (1 Reply)
Discussion started by: vivek1489
1 Replies

6. Shell Programming and Scripting

echo display problem

Hi I am facing a strange problem a=03 echo ${a} the output is 3 But i want to display it is 03 Can you people help me how to display it like 03. Thanks (2 Replies)
Discussion started by: aishsimplesweet
2 Replies

7. Shell Programming and Scripting

Display echo results in three column

Dear Friends, I have my command output which displays on one row and values are now scrollable (vertical) 3 pages. How do i display those output in three column so that i no need to scroll? Example: dcadd$cat components 1.Caluculator 2.Diary ... ... 50.Mobile 51.Battery .. ...... (12 Replies)
Discussion started by: baluchen
12 Replies

8. Shell Programming and Scripting

what does echo $$ command display

whats the value stored in $$ (2 Replies)
Discussion started by: suri
2 Replies

9. Shell Programming and Scripting

assigning variable value using echo

I am modifying an existing script and it has the following line: export SomeEnvVar=`echo ${SomeLocalVar}` Why wouldn't it just read: export SomeEnvVar=${SomeLocalVar} Is there some reason to use echo instead of a direct assignment? :confused: (2 Replies)
Discussion started by: shellburger
2 Replies

10. Shell Programming and Scripting

Echo display alignment/sort order

Hi, My script prints a few varibales as each it reads each line of a text file and then prints them on screen, however iam having problem in aligning and sorting them. what happens is this Last First Number Mark leo 87798798... (1 Reply)
Discussion started by: shackman66
1 Replies
Login or Register to Ask a Question