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!

Stripping first Character 1

Status
Not open for further replies.

GOSCO

Technical User
Sep 26, 2000
134
GB
I have a file of names and I want to strip the first letter off each name.

e.g.

FILE

andrew
john
peter

would return a file:

a;ndrew;andrew
j;ohn;john
p;eter;peter
 
GOSCO:

Here's an awk solution:

awk ' {
fc=substr($1, 1, 1)
fl=substr($1, 2, length($1))
printf("%s;%s;%s\n", fc, fl, $1);
} ' < file

fc is the first character of field 1
fl is the second character to the end of field 1.


Regards,

Ed
 
Ed, thankyou works like a treat. I must admit awks always scared me a bit. I was trying to solve the problem using shell script, which as you can probably guess proved a bit much...
 
GOSCO:

Thank you for the compliment! I appreciate it.

The best tool for solving any unix problem is probably the one you know. You might also want to post questions like this in the Unix Scripting, General Unix discussion, or even the Perl forums.

You'll probably get more varied answers than in just the SCO forum.

Regards,

Ed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top