May 2, 2006 #1 ranjank IS-IT--Management Joined May 9, 2003 Messages 176 Location 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 Joined Mar 20, 2001 Messages 8,475 Location GB Using cut: ls -ltr ranjan.abc.1122 | cut -f1,2 -d '.' Upvote 0 Downvote
May 2, 2006 #3 Annihilannic MIS Joined Jun 22, 2000 Messages 6,317 Location 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 Joined May 9, 2003 Messages 176 Location 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 Joined Jun 22, 2000 Messages 6,317 Location AU What's in the file? Annihilannic. Upvote 0 Downvote
May 2, 2006 Thread starter #6 ranjank IS-IT--Management Joined May 9, 2003 Messages 176 Location IN Well in file there are two lines which contains ranjan.abc.XXX --Ranjan. Upvote 0 Downvote
May 2, 2006 #7 Annihilannic MIS Joined Jun 22, 2000 Messages 6,317 Location 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 Joined May 9, 2003 Messages 176 Location IN Thanks a lot its working. Upvote 0 Downvote