May 2, 2006 #1 ranjank IS-IT--Management May 9, 2003 176 IN Hi, I need to filter the one ouput.Folowing is the output. ranjan.abc.1122 I want to filter only ranjan.abc only.Is there anyway in awk or sed thru which i can accomplish it. --Ranjan.
Hi, I need to filter the one ouput.Folowing is the output. ranjan.abc.1122 I want to filter only ranjan.abc only.Is there anyway in awk or sed thru which i can accomplish it. --Ranjan.
May 2, 2006 #2 KenCunningham Technical User Mar 20, 2001 8,475 GB Using cut: ls -ltr ranjan.abc.1122 | cut -f1,2 -d '.' Upvote 0 Downvote
May 2, 2006 #3 Annihilannic MIS Jun 22, 2000 6,317 AU Or with sed: [tt]echo ranjan.abc.1122 | sed 's/\.[^.]*$//'[/tt] Or with awk [tt]echo ranjan.abc.1122 | awk -F"." 'BEGIN{OFS="."}{print $1,$2}'[/tt] Annihilannic. Upvote 0 Downvote
Or with sed: [tt]echo ranjan.abc.1122 | sed 's/\.[^.]*$//'[/tt] Or with awk [tt]echo ranjan.abc.1122 | awk -F"." 'BEGIN{OFS="."}{print $1,$2}'[/tt] Annihilannic.
May 2, 2006 Thread starter #4 ranjank IS-IT--Management May 9, 2003 176 IN Thanks with both options it is working.But the problem is i'm getting the output twice when i do it on a file. E.G ranjan.abc ranjan.abc I want only one occurance and then put that in a varaible.Any help on this will be highly appreciated. --Ranjan. Upvote 0 Downvote
Thanks with both options it is working.But the problem is i'm getting the output twice when i do it on a file. E.G ranjan.abc ranjan.abc I want only one occurance and then put that in a varaible.Any help on this will be highly appreciated. --Ranjan.
May 2, 2006 #5 Annihilannic MIS Jun 22, 2000 6,317 AU What's in the file? Annihilannic. Upvote 0 Downvote
May 2, 2006 Thread starter #6 ranjank IS-IT--Management May 9, 2003 176 IN Well in file there are two lines which contains ranjan.abc.XXX --Ranjan. Upvote 0 Downvote
May 2, 2006 #7 Annihilannic MIS Jun 22, 2000 6,317 AU Instead of echo use head -1 to get the first line of the file I guess. Annihilannic. Upvote 0 Downvote
May 2, 2006 Thread starter #8 ranjank IS-IT--Management May 9, 2003 176 IN Thanks a lot its working. Upvote 0 Downvote