LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   awk substring command (https://www.linuxquestions.org/questions/linux-newbie-8/awk-substring-command-823207/)

casperdaghost 07-31-2010 08:09 AM

awk substring command
 
I configured my ssh for passwordless logins
and grepped out from this config file straight to the command - i used a substring command - but check out tuk100 and cib100 - is there any way i can just display the user, without the server number - with awk?

again i want :

ssh -l tuk tuk100 systemstart
ssh -l cib cib100 systemstart

casper% grep credman ~casper/production/prodfile.t

prodCA cas active 21954 castk100 21954 utility
prodNK cas active 21009 tuk100 21954 utility
prodUS cas active 25624 usstk100 21954 utility
prodFR cas active 23523 usfrk100 21954 utility
prodEU cas active 21461 eustk100 21954 utility
prodDE cas active 21312 destk100 21954 utility
prodIL cas active 25655 cib100 21954 utility

casper% grep credman ~casper/production/prodfile | awk '{print "ssh -l ",
substr($5,1,5), $5 ,"systemstart"}'

ssh -l castk castk100 systemstart
ssh -l tuk10 tuk100 systemstart
ssh -l usstk usstk100 systemstart
ssh -l usfrk usfrk100 systemstart
ssh -l eustk eustk100 systemstart
ssh -l destk destk100 systemstart
ssh -l cib10 cib100 systemstart

ghostdog74 07-31-2010 08:26 AM

Code:

while read -r line
do
  case "$line" in
  *credman* )
      set -- $line
      user=$5
      user=${user%%[0-9]*}
      echo "ssh -l $user $5 systemstart"
  esac
done <"file"



All times are GMT -5. The time now is 05:03 AM.