ust3
November 19, 2012, 10:32pm
1
I have a file that the format is as below ,
abc.xxx.yyy.zzz
while yyy is login ID .
And I have a script called script1 is as below
if ...
then
echo "user id"
else
...
fi
Now , I would like to have a script that can do su user to yyy first , similiar as below
if ....
then
su - yyy echo "user id"
else
....
fi
Can advise what can I do ? thanks
PikK45
November 19, 2012, 10:45pm
2
Correct me if I am wrong..
You have a file abc.xxx.LOGINID.zzz
Script1 that prints "user id"
U need script that switch user to "LOGINID" from the file then prints "user id"
I would suggest you to try something like,
if
then
su - `ls abc.xxx* | awk -F"." '{print $3}'` echo "user id"
else
fi
ust3
November 20, 2012, 1:21am
3
thanks reply ,
the script works .
I have one more question , for the file name abc.xxx.yyy.zzz
If I want to have a command which can remove the last two part of the file name ( in the above file name , the last two part is yyy.zzz ) , that means the file name becomes to aaa.xxx , can advise what can I do ?
thanks.
PikK45
November 20, 2012, 2:08am
4
In that case you will have to make use of renaming function.
mv oldname newname
ust3
November 20, 2012, 4:13am
5
thanks reply ,
But I will run it from script , not single command , and I may be have more than 1 file.
Thanks.
RudiC
November 20, 2012, 4:19am
6
What's holding your filename: a variable, a file, ...?
ust3
November 20, 2012, 4:23am
7
if file , what can I do ?
thanks.
RudiC
November 20, 2012, 4:31am
8
Very simplistic approach:
$ awk -F"." '{print $1"."$2}' file
abc.xxx
cde.ddd
kde.fer
ust3
November 20, 2012, 11:56pm
9
sorry , may be I am not explain very clearly
I have a file the file names are as below
111.222.333.444
aaa.bbb.ccc.ddd
mmm.nnn.ooo.ppp
I would like to cut last two part so that the result becomes
111.222
aaa.bbb
mmm.nnn
can advise what can I do ?
thanks
Yoda
November 21, 2012, 12:59am
10
cat file
111.222.333.444
aaa.bbb.ccc.ddd
mmm.nnn.ooo.ppp
awk -F. ' { print $1, $2 } ' OFS=. file
111.222
aaa.bbb
mmm.nnn