Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Help in awk script

Status
Not open for further replies.

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.
 
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.
 
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.
 
Well in file there are two lines which contains ranjan.abc.XXX

--Ranjan.
 
Instead of echo use head -1 to get the first line of the file I guess.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top