Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
Gi1/0/12
Gi1/0/13
Gi1/0/14
Gi1/0/15
Gi1/0/16
Gi1/0/17
Gi1/0/18
Gi1/0/19
Gi1/0/20
Gi1/0/21
Gi1/0/22
Gi1/0/23
Fa2/0/13
Fa2/0/14
Fa2/0/15
Fa2/0/16
Fa2/0/17
Fa2/0/18
Fa2/0/19
Fa2/0/20
Fa2/0/21
Fa2/0/22
Fa2/0/23
Fa2/0/24
Gi2/0/1

I want to parse this data so that

I can have the no of

regexvalue      start     end   count
Gi1/0/          12        23    12
Fa2/0/          13        13    12
Gi2/0/          1         1     1

NOTE:regex value could be changing like instead of Gi it could be te or instead of Gi/0/ it could be Gi/1 or Gi/10.but the format reamains same.

this is how i just did it using sed first and then awk:

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

#!/bin/bash
awk  '

{
 a[$1]++
 if ( a[$1] == 1 )
{
 inte[$1]=$2
}

 }
END {
for (var in inte)
print var,inte[var],a[var]
}
' 

output :

Fa2/0/ 13 12
Gi1/0/ 12 12
Gi2/0/ 1 1
share|improve this question
2  
this is not a place to ask someone else to do your own work. Try and do it (awk is the typical tool for that) and come back here with specific problem you encounter on the way. – Stephane Chazelas Mar 13 at 7:14
Concur. This sounds very much like someone trying to foist their homework off on us. – Shadur Mar 13 at 8:06
@Shadur not really, I've seen previous questions regarding some output from a router command – warl0ck Mar 13 at 9:00

closed as too localized by Stephane Chazelas, rush, manatwork, warl0ck, Shadur Mar 13 at 8:05

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

Browse other questions tagged or ask your own question.