Requirement: I need to use only grep
/cut
/join
.
I have data like:
3 abcd
23 xyz
1234 abc
I want to pipe this data to cut
and then extract columns. But, when I am using cut -d' ' -f 1,2
it treats each space as its own column divider. I would prefer the first two rows be trimmed prior to cut
. Is there a way?
Example (I have used tr
for demonstration purposes of where the spaces are here; it is not allowed in the solution):
$ echo ' 3 abcd
23 xyz
1234 abc' | cut -d' ' -f 1,2 | tr ' ' '_'
_
_23
1234_abc
Expected output:
$3 abcd
23 xyz
1234 abc