1751894 Members
5114 Online
108783 Solutions
New Discussion юеВ

echo asterisk

 
panchpan
Regular Advisor

echo asterisk

$cat /tmp/tuxob.lst
udi *****
jim 10
ant 19
ibm *****
input=`head -1 /tmp/tuxob.lst | awk '{print $NF}'`

If above is the script, then how do I put if conditions. i.e. If $input = '*****' do something. Because on putting $input displays files of current directory being expanded to echo *
5 REPLIES 5
Peter Nikitka
Honored Contributor

Re: echo asterisk

Hi,

first:
- no need for command head
- no need for command echo
You get your - doubtful - info by
awk '$NF == "*****" {print $NF;exit}' /tmp/tuxob.lst

I try to guess, what you want:
if a line has ****** as the second column, do 'something' with the first.
As an example, I check the name for existence in the NIS database in calling 'ypmatch passwd'.

awk '$NF == "*****" {cmd="ypmatch "$1" passwd"; system(cmd)}' /tmp/tuxob.lst

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
panchpan
Regular Advisor

Re: echo asterisk

Thanks Peter.
I have this code:
status | awk '{print $1 " " $3}' > /tmp/tuxob.lst
lines=`wc -l /tmp/tuxob.lst`
i=1
while [ $i -le $lines ]
do
input=`head -${i} /tmp/tuxob.lst | tail -1`
obup=`echo $input | awk '{print $2}'`
srcName=`echo $input | awk '{print $1}'`
if [ "$obup" = '*****' ]
then
echo "srcName is down"
fi
i=`expr $i + 1`
done

The file /tmp/tuxob.lst contains:
udi *****
jim 10
ant 19
ibm *****

and as an output I want to display udi and ibm.

Please advise.
Peter Nikitka
Honored Contributor

Re: echo asterisk

Ok,

let's look, if I understood the 'status' command and your script correctly! Try:

status | awk '$3 == "*****" {print $1,"is down"}'

I feel no need for a temporary file, but if you insist:
status | awk '$3 == "*****" {print $1,"is down"}
{print $1,$3 >"/tmp/tuxob.lst"}'

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Elmar P. Kolkman
Honored Contributor

Re: echo asterisk

Your script can be easily rewritten in shell to this:

status | awk '{print $1 " " $3}' > /tmp/tuxob.lst

cat /tmp/tuxob.lst | while read obup srcName
do
if [ "$obup" = '*****' ]
then
echo "srcName $srcName is down"
fi
done

Or:
grep ' [*][*]*$' /tmp/tuxob.lst | cut -f1
to do just what you want, display only the lines containing the '*****' at the end.
And there are lots of other solutions too.
Every problem has at least one solution. Only some solutions are harder to find.
James R. Ferguson
Acclaimed Contributor

Re: echo asterisk

Hi:

As a general comment, if you want to prevent file name generation, disable it with 'set -f'.

For example, compare:

# cd /tmp; echo *

...with:

# cd /tmp; set -f; echo *; set +f

Regards!

...JRF...