Reputation: 53
I have a list of phone numbers that looks like this:
LAST NAME, First name 12344 ... ...
I want in a piped sequence to take only the first last names column and paste it into a new file when only the first letter is capital. For example:
NIXON
COHEN
will be:
Nixon
Cohen
I need to do it with cut and paste commands. I know how to cut the first latter:
cut -f1 -d"," phone.txt | cut -c1
And how to cut the rest of the letters and make them not capital:
cut -f1 -d"," phone.txt | cut -c2- | tr [A-Z] [a-z]
But I can't understand how to paste them together in one piped sequence. I can use grep or sed if it helps.
Thanks,
Upvotes: 1
Views: 75
Reputation: 92854
Let's say the phone.txt
file contains:
NIXON, John 123
COHEN, Tomas 345
sed approach:
sed 's/^\(.\)\([^,]*\).*/\u\1\L\2/' phone.txt
gawk alternative:
awk -F, '{print substr($1, 1, 1) tolower(substr($1, 2))}' phone.txt
The output(for both approaches):
Nixon
Cohen
Upvotes: 3
Reputation: 139
Try this:
echo cut -f1 -d"," test.txt|cut -c1``cut -f1 -d"," test.txt|cut -c2- | tr [A-Z] [a-z]
Output : Nixon
Upvotes: 2