Sunday, December 2, 2018

shell - Treat second column with spaces as one column with awk



For a file that looks like this:



Paul    white male 34 
Jane black female 22
Sam white male 44


I would like an awk line to treat everything after the first column on the same line as a second column, so that I could run it on the above and produce the following




white male 34 
black female 22
white male 44


Currently, awk '{print $2} would only output the first word, not the rest of the line.



THanks!


Answer




One of these should work for you depending what that first space character is and the rest of your spaces are:



awk '{sub(/[^ ]+[ ]+/,"")}1' file
awk -F'\t' '{print $2}' file

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...