user1356163
user1356163

Reputation: 407

Column manipulation in UNIX

I have two fields like this

Field1 : Field2 - I have them stored in a file like this:

X : 1234
X : 4321
Y : 123
Z : 1234
Z : 4321
Z : 357

I want to transform that into this:

X : 1234
    4321
Y : 123
Z : 1234 
    4321
    357

For a given field1 field2 will be different , i.e X can't have 1234 and again 1234 but two different field1's can have the same field2, like X and Z having 1234 and 4321.

How do I go about filtering my input file to the get the required output file using BASH/KSH?

Upvotes: 1

Views: 155

Answers (1)

kev
kev

Reputation: 161864

awk -F' *: *' '{if(x!=$1)x=$1;else $1="   "}1' input.txt

output:

X : 1234
    4321
Y : 123
Z : 1234
    4321
    357

Upvotes: 5

Related Questions