substr($line,$x,$len)

Kurt Wall kwall
Mon May 17 12:02:22 PDT 2004


In a 0.5K blaze of typing glory, M.W. Chang wrote:
> >Yes. index() returns the location of a specific string; you can then
> >use match() or substr().
> 
> could you offer an example in awk?

Yes. The following prints everthing between the first character and
the first ":" in /etc/passwd. It uses index() to return the position
in of the first ":", which is then used to print the substring:

$ awk '{ print substr($0,0,index($0,":")) }' /etc/passwd
root:
bin:
daemon:
adm:
lp:
sync:
shutdown:
halt:
mail:
operator:
games:
ftp:
mysql:
rpc:
sshd:
pop:
nobody:
kwall:
postfix:

Kurt
-- 
"But don't you worry, its for a cause -- feeding global corporations
paws."



More information about the Linux-users mailing list