I've got a situation where I've got several lines, and I need two different fields out of each of them.  To be specific, I have a list of references in a bibliography and I want to get the last name and the year.Sample input:Aloise-Young, P.A. (1993). The development of self-presentation.  Self-promotion in 6- to 10-year-old children. Social Cognition, 11, 201-222.Banerjee, R. (2002). Children's understanding of self-presentational behavior: Links with mental-state reasoning and the attribution of embarrassment. Merril-Palmer Quarterly, 48, 378-404.Bennett, M., & Wellman, H. (1989). The role of second-order belief-understanding and social context in children's self-attribution of social emotions. Social Development, 9, 126-130.Desired output:Aloise-Young 1993Banerjee 2002Bennett 1989I can get the last names with cat file | cut -d, -f1I can get the years with cat file | grep -o [[:digit:]]\{4\}My problem is that now I have two separate outputs and I don't know how to combine them in the way I want.  Any ideas?  I suspect maybe awk can do what I need, but I'm a bash noob and I don't know awk yet.
Getting two fields from same line together
bash;text processing
I put your snippet in a file called alois:    sed -r 's/^([^ ,]+)[^0-9]+([0-9]+).*$/\1 \2/' alois Aloise-Young 1993Banerjee 2002Bennett 1989Quick explanation:we use sed's search & replace function s/pattern/replacement/^([^ ,]+)  means: from the beginning of line take anything that's not a space or a , and remember those. (that's that the parentheses are there for).[^0-9]+  look for anything that's not a numeric value, but ignore it.([0-9]+) take and remember any consecutive digits.*$  match everything else to the end of line.\1 \2   replace everything matched (the whole line) with the remembered values from above.