Change output format with SED - cannot get rid of CR/LF
All,
I am trying to parse the output of a router command with script. It works most of the time as this is the output format: Code:
Mu650 11.230.132.112 Fa0/0.100 11.286.72.33 06 01BD 0F42 9124K Code:
Se0/0/0:0.1111 I tried with SED to replace the CR/LF/spaces sequence but was unsuccesful so far. Instead of the above I want this: Code:
Se0/0/0:0.1111 11.12.215.49 Fa0/0.100 11.243.112.100 06 1F4E 0954 10M Thanks, Phil |
Shouldn't be too hard - are you sure there isn't a newline in there as well ?. sed is a stream editor - newlines mess with it.
|
tr and sed to break lines and format output
Quote:
If you can give me the command that you are using, may be I can do better than what I have done to help you. I copied your command's output to a file: Code:
$ cat > Test Code:
$ cat Test | tr '\n' ' ' | sed 's/Se/\nSe/g' Does that help you? (I am assuming that your lines with "Se". We can use the last field also that contains 10M/K etc.) Cheers! |
Well this is what I see when I show non-printable characters with cat:
Code:
Se0/0/0:0.1111^M$ |
Quote:
Anyway, the lines can start with all sort of things (Se/Fe/GigE/...) and the last field can be any number or end with M or K as well... I guess it would be easier to replace the obsolete spaces in the output? I am willing to share the script itself but it is a TCL script logging on to a router and issueing a command so not really necessary to show. Thanks for the help so far! |
Philip:
Try this: Code:
cat Test | tr '\n' ' ' | sed 's/[0-9][MK]/&\n/g' | sed 's/^\s//' |
I would be checking your router command to as normally you can tell it to not split over lines.
|
@ devUnix:
This is the script: Code:
#! /usr/local/bin/expect Code:
[root@myBSD]# ./toptalkers.sh 11.21.12.13 Code:
[root@myBSD]# ./toptalkers.sh 11.21.12.13 | tr '\n' ' ' |
In the future it might be advisable to tell us you are using expect, telnet and then sending a cisco command (all of which may have some impact) and then finally that you are connecting
in a Windows interface, which of course use \n\r instead of just \n. So maybe something like: Code:
./script.sh | awk 'BEGIN{RS="[\n\r]+";OFS="\t"}{$1=$1}ORS=(NR%2)?"\t":"\n"' |
All times are GMT -5. The time now is 03:39 AM. |