1834508 Members
2490 Online
110068 Solutions
New Discussion

Re: Change script

 
SOLVED
Go to solution
ust3
Regular Advisor

Change script

The below is the script to check the user no. , when user2 is login and run the script ($awk -F: -v me=$me '$1==me {print $2}' test.txt ) , the output is 2 .
$me=$(whoami)
$awk -F: -v me=$me '$1==me {print $2}' /tmp/test.txt
$2

The current test.txt is as below:
$vi test.txt
user1:1
user2:2
user3:3

now , if the test.txt is changed the format as below , can advise how to change my script to check the user no.

$vi /tmp/test.txt
user1 - 1
user2 - 2
user3 - 3
4 REPLIES 4
rajdev
Valued Contributor
Solution

Re: Change script

Hi ,

do you have the space between the user and the number ?
-- if no space then replace the -F: with -F- and it should work , so the full line will be

awk -F- -v me=$me '$1 == me { print $2}' /tmp/test1.txt

otherwise try this -- if you want the space

awk -v me=$me '$1==me {print $3}' /tmp/test.txt

Regards,
RD
ust3
Regular Advisor

Re: Change script

thx much rajdev ,

It works .
ust3
Regular Advisor

Re: Change script

sorry to reopen the thread ,

the script works fine ,
awk -v me=$me '$1==me {print $3}' /tmp/test.txt

but I found if the test.txt have # sign as below , then there is no output , can advise how to change the script ? thx

$vi /tmp/test.txt
#user1 - 1
#user2 - 2
#user3 - 3
ust3
Regular Advisor

Re: Change script

thx all,

I fixed it , please ignore the previous messages.