How to cut lines separated by multiple spaces?
cut is a Linux command that can be used to cut a line of text with a specific delimiter. I want to cut lines separated by multiple spaces like
Since the fields are separated by multiple spaces, I can’t just use cut -d’ ‘ command. What you can do is combine multiple spaces into one using tr command.
1 |
tr -s ' ' |
Here is the command I used to get all database name with Sleep connections
1 |
mysqladmin processlist | grep "Sleep" | tr -s ' ' | cut -d' ' -f8 |
Another solution is to use awk command.
1 |
mysqladmin processlist | grep "Sleep" | awk '{print $8}' |
See cut