awk or gawk question
I'm piping a file to awk in order to filter the required fields. The last column in the file will sometimes have spaces. In the example below consider the 'col4 -i' as the last column.
col1 col2 col3 col4 -i There are no delimiters in the report except for spaces so having spaces in the last column is a dirty trick. :o) Anyway, if I want to return from awk $2 and $4 then I will not get all of the last field. I've been looking in my trusty Sed & Awk O'reilly book for a way to return $2,$4 and the remainder of the line but haven't found it. Is there a way to do this with awk? |
Perhaps cut will work?
Code:
... | cut -d" " -f 2,4- |
Just concatenate the last two together :
Code:
echo "col1 col2 col3 col4 -i" | awk '{print $2,$4$5}' If you want to keep the space then just insert it : Code:
echo "col1 col2 col3 col4 -i" | awk '{print $2,$4" "$5}' |
Quote:
I love one liners. Thanks, |
Moin,
why don't you do the concatenation completely in awk? Code:
awk ' { last = ""; |
All times are GMT -5. The time now is 11:39 PM. |