0

I have a column based .txt file and I want to grep output the Common Name, having a little trouble.

V   300223164711Z       01  unknown /C=UK/O=LMG/OU=server/CN=server/name=server/emailAddress=support@kam.org
V   300223170002Z       02  unknown /C=UK/O=LMF/OU=server/CN=test/name=server/emailAddress=support@kam.org
V   300223170935Z       03  unknown /C=UK/O=risk/OU=server/CN=risk/name=server/emailAddress=support@kam.org

My current grep output does the following:

tail -n +2 index.txt | grep "^V" | cut -d '/' -f 5 | nl -s ') '
     1) CN=test
     2) CN=risk

I only want the name to be the output, 'test' or 'risk'. What would be the simplest way to achieve this?

Kam-ALIEN
  • 19
  • 5

2 Answers2

0

In awk you can do it on this way (assuming the place of CN is always the same:

awk -F\/ '$5~"test"|| $5~"risk" {gsub("CN=","",$5);print $5}'

To add the number of the line where you find a CN records you can use code like this:

awk -F\/ '$5~"test"|| $5~"risk" {gsub("CN=","",$5);print NR") "$5 }'
Romeo Ninov
  • 3,195
  • 2
  • 13
  • 16
0

sed should be one of your friends

echo CN=test | sed -e 's/CN=//'
test
Francozen
  • 163
  • 5