0

I've been using awk in an Expect script to edit a text file that contains information about a switch, so far the text file looks like this:

Device ID Local Intrfce 
  BIOTERIO Gig 1/0/6 
  N7K-LAN(JAF1651ANDL) Gig 1/0/1 134 
  LAB_PESADO Gig 1/0/11 
  Arquitectura_Salones Gig 1/0/9 129 
  CIVIL_253 Gig 1/0/4 
  Arquitectura Gig 1/0/3 
  ING_CIVIL_DIR Gig 1/0/10 
  ING_CIVIL Gig 1/0/7 
  Ingenieria_Posgrado --More-- 
  Device ID Local Intrfce 
  Gig 1/0/8 134 
  Biblio_Barragan Gig 1/0/2 
  Electronica_Edif_3 Gig 1/0/5 127 
  Barragan_3750>exit Connection closed by foreign host. 
  ]0;cesar@cesar-HP-Pavilion-15-Note 

As the script handles with multiple lines output, te label --More-- is printed in the text file, as well the column name Device ID Local Intrfce is printed twice.

I want the file to look like this:

Device ID Local Intrfce 
  BIOTERIO Gig 1/0/6 
  N7K-LAN(JAF1651ANDL) Gig 1/0/1 134 
  LAB_PESADO Gig 1/0/11 
  Arquitectura_Salones Gig 1/0/9 129 
  CIVIL_253 Gig 1/0/4 
  Arquitectura Gig 1/0/3 
  ING_CIVIL_DIR Gig 1/0/10 
  ING_CIVIL Gig 1/0/7 
  Ingenieria_Posgrado Gig 1/0/8 134 
  Biblio_Barragan Gig 1/0/2 
  Electronica_Edif_3 Gig 1/0/5 127 
  Barragan_3750>exit Connection closed by foreign host. 
  ]0;cesar@cesar-HP-Pavilion-15-Note 

I Know how to find a specific word, but it could be in any column because that depends on terminal length.

just to recap, I want to find the word --More-- and delete it with the following line.

Any help?

Thanks.

Update:

this did the work: sed '/--More--/{N;N; s/--More--.*\n[ \t]*//}' in the expect script the syntaxis is:

send -- "sed '/--More--/{N;N; s/--More--.*\\n\[ \\t\]*//}' TablaCDP.dat > CDPyPuerto.dat \r"
2

With sed:

sed '/--More--/{s///;n;d;}'

The awk equivalent:

awk 'sub(/--More--/, "") {print; getline; next}; {print}'
  • Thanks, this is a really good approach, but I need to keep the word Ingenieria_Posgrado following by Gig 1/0/8 134 in the same line. With this solution, the whole line is deleted. – Cesar Alejandro Villegas Yepez Feb 8 '17 at 16:10
  • @CesarAlejandroVillegasYepez see if sed '/--More--/{N;N; s/--More--.*\n[ \t]*//}' helps.. – Sundeep Feb 8 '17 at 16:19
  • It worked perfectly @Sundeep thanks a lot , I just update the post. – Cesar Alejandro Villegas Yepez Feb 8 '17 at 16:34
  • @CesarAlejandroVillegasYepez, sorry the N should have been a n. – Stéphane Chazelas Feb 8 '17 at 16:52
0

Perl can do it too:

$ perl -pe '$_ = "" if($. > 1 and $_ =~ /Device ID Local Intrfce/); $_ =~ s/--More--//;'  input.txt   
Device ID Local Intrfce 
  BIOTERIO Gig 1/0/6 
  N7K-LAN(JAF1651ANDL) Gig 1/0/1 134 
  LAB_PESADO Gig 1/0/11 
  Arquitectura_Salones Gig 1/0/9 129 
  CIVIL_253 Gig 1/0/4 
  Arquitectura Gig 1/0/3 
  ING_CIVIL_DIR Gig 1/0/10 
  ING_CIVIL Gig 1/0/7 
  Ingenieria_Posgrado  
  Gig 1/0/8 134 
  Biblio_Barragan Gig 1/0/2 
  Electronica_Edif_3 Gig 1/0/5 127 
  Barragan_3750>exit Connection closed by foreign host. 
  ]0;cesar@cesar-HP-Pavilion-15-Note 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.