Monday, April 29, 2024
7
rated 0 times [  7] [ 0]  / answers: 1 / hits: 1196  / 2 Years ago, fri, april 1, 2022, 8:36:38

I would like to edit a list of MACs in bl:ab:la:bl:ab:la format >> in to blab.labl.abla format. Each MAC is in a line.
I'm new in the use of AWK or SED but I'm almost sure that it can be performed using any of those commands.


Is there any way to set the column position in where a character (a dot) has to be inserted (using sed or awk) in order to accomplish this task?


I've read the sed man page but It didn't get any clear.


More From » command-line

 Answers
1

With awk:


awk -F: '{print $1$2"."$3$4"."$5$6}'

-F: will set : as the field separator and print $1$2"."$3$4"."$5$6 will print fields $1 and $2 then print a . and so on ... the rest is self explanatory.


Example:


$ echo "bl:ab:la:bl:ab:la" | awk -F: '{print $1$2"."$3$4"."$5$6}'
blab.labl.abla

It can also read from a file like so:


awk -F: '{print $1$2"."$3$4"."$5$6}' file

and modify the file in-place(i.e. edit the original file) like so:


gawk -i inplace -F: '{print $1$2"."$3$4"."$5$6}' file

[#326] Sunday, April 3, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
fulpu

Total Points: 116
Total Questions: 118
Total Answers: 104

Location: Solomon Islands
Member since Fri, Oct 8, 2021
3 Years ago
fulpu questions
Wed, Mar 16, 22, 15:25, 2 Years ago
Wed, Aug 24, 22, 22:59, 2 Years ago
Tue, Dec 20, 22, 22:33, 1 Year ago
Tue, Jan 3, 23, 13:19, 1 Year ago
;