1

I have a pipe delimited file like this where the second column is the key that groups the ids in the first column.

456566|23233|
456545|23233|
456745|23233|
456456|23234|
456356|23234|

I am trying to create a file like this where the first id gets repeated based on the id in the second field and remaining ids for that group in the second column. I am would like to learn how to do this using any utilities like awk

output

456566|456545
456566|456745
456456|456356

1 Answer 1

3
$ cat tst.awk
BEGIN { FS=OFS="|" }
$2 != prevKey {
    firstId = $1
    prevKey = $2
    next
}
{ print firstId, $1 }

$ awk -f tst.awk file
456566|456545
456566|456745
456456|456356
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .