Niresh
Niresh

Reputation: 667

Rearrange Outputs Bash

I Have Output Like This

00:00.0 0600: 8086:2e20 (rev 03)
00:01.0 0604: 8086:2e21 (rev 03)
00:03.0 0780: 8086:2e24 (rev 03)
00:19.0 0200: 8086:10ce
00:1a.0 0c03: 8086:3a37
00:1a.1 0c03: 8086:3a38
00:1a.2 0c03: 8086:3a39
00:1a.7 0c03: 8086:3a3c
00:1b.0 0403: 8086:3a3e
00:1c.0 0604: 8086:3a40
00:1c.2 0604: 8086:3a44
00:1c.3 0604: 8086:3a46
00:1d.0 0c03: 8086:3a34
00:1d.1 0c03: 8086:3a35
00:1d.2 0c03: 8086:3a36
00:1d.7 0c03: 8086:3a3a
00:1e.0 0604: 8086:244e (rev 90)
00:1f.0 0601: 8086:3a18
00:1f.2 0106: 8086:3a22
00:1f.3 0c05: 8086:3a30
01:00.0 0300: 10de:0640 (rev a1)
03:00.0 0101: 11ab:6101 (rev c0)

I Need to Get The Output of Each Line as:

610111ab <-- Last Line
064010de <-- Line Before Last One

Upvotes: 0

Views: 124

Answers (4)

Digital Trauma
Digital Trauma

Reputation: 16016

Pure solution:

re="([0-9a-f]{4}):([0-9a-f]{4})"
cat output.txt | while read l ; do [[ $l =~ $re ]] && echo ${BASH_REMATCH[2]}${BASH_REMATCH[1]}; done

Upvotes: 2

svante
svante

Reputation: 1385

Awk solution :

awk -F':| ' '{print $6$5}' output

Upvotes: 1

glenn jackman
glenn jackman

Reputation: 247142

sed 's/.*: \(....\):\(....\).*/\2\1/'

I also am confused by your required output of each line. If you want it in reverse order, pipe the sed output into tac.

Upvotes: 1

LMC
LMC

Reputation: 12822

this could help

echo "03:00.0 0101: 11ab:6101 (rev c0)" | gawk 'BEGIN{FS="("}; { print $1 }' | gawk 'BEGIN{FS=":"; OFS="" };{ print $4,$3 }' | tr -d ' '

Upvotes: 2

Related Questions