INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

avoid creating temp file

avoid creating temp file

(OP)
hello,

I have following form of input from command:

CODE --> text

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 --> text

# 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)?

RE: avoid creating temp file

(OP)
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?

RE: avoid creating temp file

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close