Need help with paste command using variables

How can I accomplish this? I basically want to merge two variables onto the same line. I can do it with two FILES this way:

[ngreenfield@xxxxxx tmp]$ cat /tmp/users_in.list | awk -F "," '{print $2}' | cut -c -1 > first.initial
[ngreenfield@xxxxxx tmp]$ awk -F "," '{print $1}' /tmp/users_in.list | awk '{print $1}' > last.name
[ngreenfield@xxxxxx tmp]$ paste first.initial last.name | awk '{print $1$2}'
AAtun
JBatrez
SBevz
RCantley
TCheng
KChow
TCronk
JElizalde
KFindlay
CFrary
WHall
JHuang
AHunt
KJeffries
JKubiak
TMelton
CMolloy
ANg
SPatel
JPuckett
BRhoades
ARuiz
JSchmitt
TSenfleben
SSpangler
MSteingrebe
JTanner
DTrinh
JWalters
GWendover
DWright
PYara
EAcquisto
SBohannon
MChurchill

For some reason though I can't do this with variables:

[ngreenfield@xxxxxx tmp]$ FIRSTINITIAL=`cat /tmp/users_in.list | awk -F "," '{print $2}' | cut -c -1`
[ngreenfield@xxxxxx tmp]$ LASTNAME=`awk -F "," '{print $1}' /tmp/users_in.list | awk '{print $1}'`
[ngreenfield@xxxxxx tmp]$ paste $FIRSTINITIAL $LASTNAME | awk '{print $1$2}'
paste: A: No such file or directory
[ngreenfield@pdtscope003 tmp]$

Any ideas?

The paste command is for files.

By the way, there are many simpler ways to do what you are attempting to do - since only using one file. Or, maybe that was simply your example.

Joey,

Basically I am given a list of name phonebook style:

Otun,Bill A
Bald,Jared P
Berch,Sarah O
Connor,Randy J
Church,Tom

I want to be able to output them as firstinitial.lastname format, like:

botun
jbald
sberch
rconnor
tchurch

So what would you recommend as the best way to resolve this? I had been using awks to get a list of first initial then lastname while filtering out the middle initial and trying to then mash them together.

Thanks,

Nick

awk -F, '{print substr ($2,1,1)$1}' file
BOtun
JBald
SBerch
RConnor
TChurch

or

awk -F, '{print tolower(substr ($2,1,1)$1)}' file
botun
jbald
sberch
rconnor
tchurch
1 Like

Another version in Perl:

perl -ne 'print "\L${2}\L${1}\E\n" if(/(\w+),(\w).*/)' file
botun
jbald
sberch
rconnor
tchurch

Rudi,

Thanks, thats exactly what I'm looking for!

-Nick