grep out and fix a section


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep out and fix a section
# 1  
Old 06-22-2011
grep out and fix a section

I have a file that contains a section of information like this:
Code:
10_82_150_13.netshhcp Server 10.82.150.13 Scope 10.82.128.0 Add reservedip 10.82.130.54 0060b09f4b74 "PR_EMD_METALS1.san.local" "TSF 5th floor room 507 h
plj4000" "BOTH"
10_82_150_13.netshhcp Server 10.82.150.13 Scope 10.82.128.0 Add reservedip 10.82.133.146 0709080302 "LAG CONTROL SYS" "LAG CONTROL SYS" "BOTH"

Basically the issue is the 0060b09f4b74 part needs to be 12 digits long. which this example is fine.

or the next entry 0709080302 its not.

What I would like is a way to fix these short MAC's and replace with 12 zeros 000000000000 and pipe the new file out

is there a quick command line I can do? perl/sed/awk??

I tried these with no success:
Code:
grep s/Add reservedip \([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\) [a-f0-9]{4,11}/Add reservedip \1 000000000000/ 10_82_150_13.netsh

grep: reservedip: No such file or directory
grep: ([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}): No such file or directory
grep: [a-f0-9]4/Add: No such file or directory
grep: [a-f0-9]11/Add: No such file or directory
grep: reservedip: No such file or directory
grep: 1: No such file or directory
grep: 000000000000/: No such file or directory

---------------------------------------------------------------------------
Code:
Perl -pe 's{\s[a-f0-9]{4,11}\s}{ 000000000000 }' 10_82_150_13.netsh

However, I see a few lines that have more digits for MAC
Code:
Dhcp Server 10.82.150.13 Scope 10.82.128.0 Add reservedip 10.82.135.1 0111111222223333 "switch setup" "check whoip for info" "BOTH"

and too short ones like: (( aa ))
Code:
Dhcp Server 10.82.150.13 Scope 10.82.128.0 Add reservedip 10.82.135.133 aa "security" "camera" "BOTH"


Thanks for your help in advance

Last edited by Franklin52; 06-23-2011 at 03:44 AM.. Reason: Please use code tags
# 2  
Old 06-22-2011
like this?
Code:
awk '{if(length($9)!=12) $9="000000000000"; print} '

# 3  
Old 06-22-2011
Hi Mirni,

How would I run/use this?

sorry to sound dumb
# 4  
Old 06-22-2011
Just pass it a filename as argument:

Code:
awk '{if(length($9)!=12) $9="000000000000"; print}' file

# 5  
Old 06-22-2011
Hi Mirni,

I suspected that, I did run it as
Code:
$ awk '{if(length($9)!=12) $9="000000000000"; print}'10_82_150_13.netsh
awk: {if(length($9)!=12) $9="000000000000"; print}10_82_150_13.netsh
awk:                                                          ^ syntax error

and:
Code:
$ awk '{if(length($9)!=12) $9="000000000000"; print}' 10_82_150_13.netsh
Aborted (core dumped)

Code:
$ less gawk.exe.stackdump
Stack trace:
Frame     Function  Args
0028C3E4  769B1194  (00000120, 0000EA60, 00000000, 0028C508)
0028C3F8  769B1148  (00000120, 0000EA60, 000000A4, 0028C4EC)
0028C508  610C92FA  (00000000, 00000120, 0028C528, 00000000)
0028C5E8  610C6057  (00000000, 00000000, 00000000, 00000000)
0028C638  610C643C  (00001BC4, 0028C660, 0028C6F0, 610926C9)
0028C6F8  610C6551  (00001BC4, 00000006, 0028C728, 610C65F5)
0028C708  610C658C  (00000006, 0028CE80, 00000000, 00000000)
0028C728  610C65F5  (00000000, 00000000, 00000000, 00000000)
0028C798  610F52DD  (00B65760, FFFFFFFF, 00000000, 00000000)
0028C7E8  0041C184  (00000000, 00000000, 00010000, 00B655D0)
0028C828  00413E24  (00B656E8, 0000000A, 0028CC48, 610024E2)
0028C988  00436EDD  (00B656E8, 00000000, 0028C9D8, 00000000)
0028CAE8  00436E91  (00B65738, 0028FF40, 00B7DB98, 61073E66)
0028CC48  00436DC0  (00B654E0, 00000000, 0028CD28, 00425B91)
0028CC58  00423AD8  (00B65A10, 00445716, 00000000, 00446220)
0028CD28  00425B91  (00000000, 00000000, 0028CD68, 61007038)
End of stack trace (more stack frames may be present)
gawk.exe.stackdump (END)


Last edited by Franklin52; 06-23-2011 at 03:45 AM.. Reason: Please use code tags
# 6  
Old 06-22-2011
Sample file

Here is the sample
# 7  
Old 06-22-2011
hmmmm... , you actually managed to crash awk... :-o
You do need a space between the last quote and filename.
What version of awk do you have? Please post
Code:
awk --version

---------- Post updated at 12:06 PM ---------- Previous update was at 12:02 PM ----------

Same thing in perl:
Code:
perl -lane '{$F[8]="000000000000" if(length($F[8]) != 12); print "@F";}'

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep a section from an UNIX file obtaining only part of the data

Hello, I have a log file that has several sections "BEGIN JOB, End of job" like in the following example: 19/06/12 - 16:00:57 (27787398-449294): BEGIN JOB j1(27787398-449294) JOB1 19/06/12 - 16:00:57 (27787398-449294): DIGIT: 0 number of present logs : 1 19/06/12 - 16:00:57... (4 Replies)
Discussion started by: mvalonso
4 Replies

2. Shell Programming and Scripting

How to Grep of by section?

I have a script that outputs this as a file John Smith ---------------- memberOf: example1;sampletest;test memberOf: example2;sampletest;test memberOf: example3;sampletest;test memberOf: example4;sampletest;test A Member of 4 Groups Sally Smith ---------------- memberOf:... (4 Replies)
Discussion started by: ajetangay
4 Replies

3. Shell Programming and Scripting

Grep text and see all section

Hello I am looking for a way to look in files and to grep text and see the all section of the text ! Sharon123 deed 10000 class 360 ! sharon456 2000 deed ! Sharon789 live 3000 ! To grep "deed "an see the all section (5 Replies)
Discussion started by: sharong
5 Replies

4. Shell Programming and Scripting

Grep or print each section of a file on one line with a separator

I can obtain information from itdt inventory command however it display as below, I'd like to print each entity on one line but seperated by : the file is something like and each section ends with Volume Tag Drive Address 256 Drive State ................... Normal ASC/ASCQ... (3 Replies)
Discussion started by: gefa
3 Replies

5. Shell Programming and Scripting

Prepend first line of section to each line until the next section header

I have searched in a variety of ways in a variety of places but have come up empty. I would like to prepend a portion of a section header to each following line until the next section header. I have been using sed for most things up until now but I'd go for a solution in just about anything--... (7 Replies)
Discussion started by: pagrus
7 Replies

6. Shell Programming and Scripting

Extract section of file based on word in section

I have a list of Servers in no particular order as follows: virtualMachines="IIBSBS IIBVICDMS01 IIBVICMA01"And I am generating some output from a pre-existing script that gives me the following (this is a sample output selection). 9/17/2010 8:00:05 PM: Normal backup using VDRBACKUPS... (2 Replies)
Discussion started by: jelloir
2 Replies

7. UNIX for Dummies Questions & Answers

how can i extract text section via grep

hi, i have a very long text file. i need to extract with grep command a certain part. for example text file include 1ooo rows: 1.... 2... 3... . . . 1000 i want to view with grep only rows 50-100. any ideas will be appreciated thanks... (8 Replies)
Discussion started by: meny
8 Replies

8. Post Here to Contact Site Administrators and Moderators

New Section

Just like we have a section "Unix for dummies..." , why not have a section on UNIX BACKUP AND RECOVERY Thanks :) (3 Replies)
Discussion started by: kapilv
3 Replies

9. Post Here to Contact Site Administrators and Moderators

New section

What are the chances of possibly posting some of the more common how-to type stuff for the newbies so we can avoid the repititious stuff that appears every other day? Not so much like a Q&A forum, but more like a reference area for the mundane stuff. Beyond searching the forum, I think people... (3 Replies)
Discussion started by: ober5861
3 Replies
Login or Register to Ask a Question