justleen
August 1st, 2008, 01:15 PM
I have a CSV text file, which contains userid,first and lastname
a line looks like
DRN90002; Doe, John
What I need from the user name is the first three letters as uppercase, and i need the whole userid as lowercase.
What i have so far is this:
while read line; do
USERNAME=${line%;*}
USERNAME=$(echo $USERNAME | tr A-Z a-z)
REGIO=${line:0:3}
echo $REGIO $USERNAME
done < ${NEWFILE}
Now.. this does exactly what I want. But, I am wondering, can I somehow combine the 2 lines that create the $USERNAME that I need?
As in, can I grab the first part of the line and to a tr on it, without splitting over 2 lines (and adding another proccess since I launch tr)?
a line looks like
DRN90002; Doe, John
What I need from the user name is the first three letters as uppercase, and i need the whole userid as lowercase.
What i have so far is this:
while read line; do
USERNAME=${line%;*}
USERNAME=$(echo $USERNAME | tr A-Z a-z)
REGIO=${line:0:3}
echo $REGIO $USERNAME
done < ${NEWFILE}
Now.. this does exactly what I want. But, I am wondering, can I somehow combine the 2 lines that create the $USERNAME that I need?
As in, can I grab the first part of the line and to a tr on it, without splitting over 2 lines (and adding another proccess since I launch tr)?