Register
It is currently Sat Sep 20, 2014 7:58 am

bash script with awk if & dialog


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Sun Dec 25, 2011 12:18 pm   

Joined: Sun Dec 25, 2011 12:01 pm
Posts: 2
Hey, it may be a simple question for you, I try to create script with dialog witch need to change a file in my case is eth configuration file. The problem occurs when in file is for example "IPADDR=" becouse I use dialog --menu I have got error.
The script looks like
Code:
eth0=/conf-file-eth0
items=$(awk -F\= '{print $1,$2}' $eth0)
   dialog --title "Eth0" \
          --menu "Edit :" 0 0 0 $items 2> $tmpfile1

When line in config file is like "IPADDR=1.1.1.1" then script works good but when is "IPADDR=" error is due to missing argument for dialog. How can I add "IF" function or something else to make it work ? for example i would like to "IF" function add "1.1.1.1" for $2 when it is blank in the configuration file.

I tried something like that
Code:
items=$(awk  -F\= '{ if [ $2=="" ]; then 
        $2="0.0.0."
        print $1,$2
        else
        print $1,$2
         fi }' $eth0  )

But i know is wrong.

Thanks for your help


Top
 Profile  
 PostPosted: Sun Dec 25, 2011 1:18 pm   

Joined: Sun Dec 25, 2011 12:01 pm
Posts: 2
I have done it,

the way to do it is
Code:
items=$(awk -F\= ' $2 == "" {print $1,"0.0.0.0"}
                $2 !="" {print $1,$2}'  eth0 )


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP