1

I'm trying to delete this: --More-- from a .dat file, this is a fragment of the file to give an example:

Device ID: N7K-LAN(JAF1651ANDL)
  IP address: 148.228.4.192
Interface: GigabitEthernet0/1,  Port ID (outgoing port): Ethernet7/19
Device ID: CIRC_INF_IDF1
  IP address: 148.228.107.252
Interface: FastEthernet0/20,  Port ID (outgoing port): GigabitEthernet0/1
  IP address: 148.228.107.252
Device ID: CIRC_INF_IDF3
  IP address: 148.228.107.250
 --More--         Interface: FastEthernet0/23,  Port ID (outgoing port): GigabitEthernet0/1
  IP address: 148.228.107.250
Device ID: CIRC_INF_IDF2
  IP address: 148.228.107.251
Interface: FastEthernet0/22,  Port ID (outgoing port): GigabitEthernet0/1
  IP address: 148.228.107.251
Device ID: SEP1CAA0711CFBE
 --More--           IP address: 148.228.199.103
Interface: FastEthernet0/2,  Port ID (outgoing port): Port 1
Device ID: SEP1CAA0711CD67
  IP address: 148.228.199.154
Interface: FastEthernet0/5,  Port ID (outgoing port): Port 1

Using a Hex text editor I've identified the non-visible characters enter image description here

Now I'm trying to delete the whole sequence of characters but I haven't had succeeded,

those are my tries:

tr -d --More--           < tabladetallada.dat >temporaltabla.dat

tr -d '\015' '\012' '\20' '\055' '\055' '\115' < tabladetallada.dat >temporaltabla.dat

sed 's/--More--␣//' tabladetallada.dat>tabladetallada2.dat

tr -d ' --More-- ^H^H^H^H^H^H^H^H^H        ^H^H^H^H^H^H^H^H^H' < tabladetallada.dat >temporaltabla.dat

Any help?

Thanks.

this is how it looks in vi:

Device ID: N7K-LAN(JAF1651ANDL)^M
  IP address: 148.228.4.192^M
Interface: GigabitEthernet0/1,  Port ID (outgoing port): Ethernet7/19^M
Device ID: CIRC_INF_IDF1^M
  IP address: 148.228.107.252^M
Interface: FastEthernet0/20,  Port ID (outgoing port): GigabitEthernet0/1^M
  IP address: 148.228.107.252^M
Device ID: CIRC_INF_IDF3^M
  IP address: 148.228.107.250^M
 --More-- ^H^H^H^H^H^H^H^H^H        ^H^H^H^H^H^H^H^H^HInterface: FastEthernet0/23,  Port ID (outgoing port): GigabitEthernet0/1^M
  IP address: 148.228.107.250^M
Device ID: CIRC_INF_IDF2^M
  IP address: 148.228.107.251^M
Interface: FastEthernet0/22,  Port ID (outgoing port): GigabitEthernet0/1^M
  IP address: 148.228.107.251^M
Device ID: SEP1CAA0711CFBE^M
 --More-- ^H^H^H^H^H^H^H^H^H        ^H^H^H^H^H^H^H^H^H  IP address: 148.228.199.103^M
Interface: FastEthernet0/2,  Port ID (outgoing port): Port 1^M
Device ID: SEP1CAA0711CD67^M
  IP address: 148.228.199.154^M
Interface: FastEthernet0/5,  Port ID (outgoing port): Port 1^M
Device ID: SEP1CAA0711D11A^M
  IP address: 148.228.199.4^M
Interface: FastEthernet0/10,  Port ID (outgoing port): Port 1^M
Device ID: SEPece1a985bb74^M
  IP address: 148.228.199.21^M
Interface: FastEthernet0/12,  Port ID (outgoing port): Port 1^M
Device ID: SEPf84f5794c5c4^M
  IP address: 148.228.199.23^M
Interface: FastEthernet0/11,  Port ID (outgoing port): Port 1^M
Device ID: SEP1CAA0711D276^M
  IP address: 148.228.199.102^M
 --More-- ^H^H^H^H^H^H^H^H^H        ^H^H^H^H^H^H^H^H^HInterface: FastEthernet0/9,  Port ID (outgoing port): Port 1^M
Device ID: SEPece1a985b5d5^M
  IP address: 148.228.199.24^M
Interface: FastEthernet0/14,  Port ID (outgoing port): Port 1^M
Device ID: SEP1CAA0711497C^M
Interface: FastEthernet0/4,  Port ID (outgoing port): Port 1^M
Device ID: SEPf84f5794c8c2^M
  IP address: 148.228.199.22^M
Interface: FastEthernet0/3,  Port ID (outgoing port): Port 1^M
Device ID: Circulo_Camaras4^M
 --More-- ^H^H^H^H^H^H^H^H^H        ^H^H^H^H^H^H^H^H^H  IP address: 148.228.101.5^M
Interface: FastEthernet0/24,  Port ID (outgoing port): GigabitEthernet1/0/24^M
  IP address: 148.228.101.5^M
4
  • 1
    Note to answerers: the markdown rendering eats the characters. If you want to test your solutions, click on the edit link and copy the example directly from the question.
    – terdon
    Apr 25, 2017 at 16:37
  • 1
    What do you want to delete exactly? The ---More--- + unprintable characters? Or should we also delete the spaces?
    – terdon
    Apr 25, 2017 at 16:38
  • 2
    tr doesn't delete sequences. It can delete all occurrences of characters in a given set, which would help remove the backspace characters, but you'll need something more (like sed) to remove the sequence --MORE--
    – Fox
    Apr 25, 2017 at 16:38
  • thanks to all of you, I've solved this problem, i used tr -cd '\11\12\15\40-\176' to delete the "garbage " and then sed 's/--More--␣// to delete that part. Apr 25, 2017 at 16:44

2 Answers 2

3
sed -e 's/^[ ]*--More--.*\x8//' -e 's/\xD$//'

  • Instead of writing s/ */../ my personal preference is s/[ ]*/../ as it makes the * visibly attached to the atom on it's left when it's a space/TAB.
  • GNU sed has the hex matching facility with the \xhexdigit sequence.
6
  • Why are you using a character class for a single character? Why not just ` *` (that's a space before the asterisk)? Oh, and it would be great if you could explain the \x notation.
    – terdon
    Apr 25, 2017 at 16:50
  • I had got a different solution, but then I noticed this is better. Thanks a lot. Apr 25, 2017 at 17:12
  • Actually Terdon's solution is much superior. Why? If there's even one ^H towards the end of line, then this sed will eat up the whole line and leave you with only --More-- :-( When I saw that [^\s\w] I realized the shortcoming of my sed methd. HTH.
    – user218374
    Apr 25, 2017 at 17:16
  • Well, superior after you fixed my stupid mistake, you mean ;). Anyway, please remember to vote when you see good (or bad) solutions. You've been here for almost 3 months now and haven't cast a single vote! Votes are essential for pushing bad answers down and good answers to the top.
    – terdon
    Apr 25, 2017 at 18:15
  • I was referring to the sed method. And I am not able to vote uptil now. S.E. doesn't allow me.
    – user218374
    Apr 26, 2017 at 4:35
2

The simplest solution is to think the other way around. Instead of trying to define the characters you don't want, define the ones you do want and remove anything else:

sed 's/--More--[^ a-zA-Z0-9]*//' file 

That will delete the string --More-- and 0 or more characters after it that aren't a space, a letter or a number. Depending on your data, you might have to tweak that set a little (e.g. also allow _ or whatever you need).

Now, the first --More-- in your question seems to contain contains backspace characters (octal 010, Hex 7, ASCII \b), so you could also just do:

perl -pe 's/[\b]//g' file

Or, to remove the --More-- as well:

perl -pe 's/--More--[\b]+//g' file
2
  • There's a run of spaces in the middle of the backspaces (to overwrite the --More--, I suppose), so maybe something like s/ --More-- \x8+ +\x8+//g
    – ilkkachu
    Apr 25, 2017 at 18:02
  • @ilkkachu or just s/\x8+//g, then.
    – terdon
    Apr 25, 2017 at 18:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .