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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

avoid creating temp file 1

Status
Not open for further replies.

w5000

Technical User
Nov 24, 2010
223
PL
hello,

I have following form of input from command:

Code:
asd1=300
asd2=300
asd3=200
asd4=400
asd5=300

I have a script which already does what I want - returning asd_status=all300 in case all asd[0-9]*=300, and returingng asd_status="with_list_of_not_300":

Code:
# cat ./test_
echo "asd1=$1\nasd2=$2\nasd3=$3\nasd4=$4\nasd5=$5" > /tmp/testfile
if grep -vq \=300$ /tmp/testfile
then
echo asd_status=$(grep -v \=300$ /tmp/testfile|tr '\n' ','|sed s/\,$//g)
else
echo asd_status=all300
fi


# ./test_ 300 200 300 100 300
asd_status=asd2=200,asd4=100
# ./test_ 300 300 300 100 300
asd_status=asd4=100
# ./test_ 300 300 300 300 300
asd_status=all300

could we rid of /tmp/testfile and get the expected result just piping this sample input: echo "asd1=$1\nasd2=$2\nasd3=$3\nasd4=$4\nasd5=$5" | .... ? (eg. awking it)?
 
Like this ?
Code:
echo "asd1=$1\nasd2=$2\nasd3=$3\nasd4=$4\nasd5=$5" | awk '
/\=300$/{next}
{++n;s=s","$0}
END{print "asd_status="(n?substr(s,2):"all300")}
'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
works briliant - I only forgot about case when command generates no input - how to modify awk so it outputs nothing when | gave no input lines to awk?
 
ok, I figured it out

awk '/\=300$/{next}{++n;s=s","$0}END{if (NR) print "asd_status="(n?substr(s,2):"all300")}'

thank you

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top