A couple of general tips (besides the DOS line ending issue):
cat
is for concatenating files, it's not the only tool that can read files! If a command doesn't read files then use redirection like command < file
.
You can set the field separator with the -F
option so instead of:
cat foo | awk 'BEGIN{FS="|"} {print $2 " " $1}'
Try:
awk -F'|' '{print $2" "$1}' foo
This will output:
com.emailclient.account name1@gmail.com
com.socialsite.auth.accoun name2@msn.com
To get the desired output you could do a variety of things. I'd probably split()
the second field:
awk -F'|' '{split($2,a,".");print a[2]" "$1}' file
emailclient name1@gmail.com
socialsite name2@msn.com
Finally to get the first character converted to uppercase is a bit of a pain in awk
as you don't have a nice built in ucfirst()
function:
awk -F'|' '{split($2,a,".");print toupper(substr(a[2],1,1)) substr(a[2],2),$1}' file
Emailclient name1@gmail.com
Socialsite name2@msn.com
If you want something more concise (although you give up a sub-process) you could do:
awk -F'|' '{split($2,a,".");print a[2]" "$1}' file | sed 's/^./U&/'
Emailclient name1@gmail.com
Socialsite name2@msn.com
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…