Sponsored Content
Top Forums Shell Programming and Scripting Add NA When String is not found Post 303024423 by dis0wned on Monday 8th of October 2018 10:31:19 AM
Old 10-08-2018
Sorry been away for a week. Ok, heres what Im doing:

There are several command outputs from routers and switches that have different information that is useful when looking to redesign. These are not log files. The format is all over the board between files. Ive been parsing through these files individually, extracting the data that I find valuable, formatting it for CSV.

I start with one file, parse through, create a file, then use one of the fields like a key field (VLAN or interface). When I make a match (depending on which field I am keying on, I add the correlating information to the end of the file in CSV format that I can import into a spreadsheet for quick reference).

As Ive been going through the files, when I match on one key word or another, if they keyword isnt present in the show file then it is throwing off the rest of the "complete file"
Im not trying to be cryptic or dodgy with my answers, I find that at times I am not great at explaining myself.
Here is an output example pulled from a spreadsheet: (first line had matches in all fields, second was missing a match which through all results to the left / incorrect fields in the output)

Code:
Hostname	Port	Name	Status	Vlan	Duplex	Speed	Type	VLAN Name	CDP NE Hostname	CDP NE IP	CDP NE Platform	CDP NE Capabilities	Local Interface	Remote Interface	CDP NE Software	CDP NE Software	CDP NE Version	CDP NE Release	CDP NE VLAN	CDP NE Admin IP	POE Admin	POE Oper	POE Power	POE Watts	POE Device	POE Class


Tech.log	Te4/4	inactive	1	full	auto	No XCVR	default	NA	NA	NA	NA	NA	NA	NA	NA	NA	NA	NA	NA	NA	NA	NA	NA	NA	NA	NA
Tech.log	Gi5/1	W-01 Ge0/	connected	240	a-full	a-1000	10/100/1000-TX	Voice-Primary	.cisco.local	10..1	Cisco CISCO2911/K9	Router Switch IGMP	Gi5/1	Gi0/0	Cisco IOS Software	C2900 Software (C2900-UNIVERSALK9-M)	Version 15.2(3)T	RELEASE SOFTWARE (fc1)		auto	ff	0	0	n/a	n/a

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Display only found string

Is there a way for grep to output only the found string and not the whole line? I have a ksh script which reads in a file and loops through every line looking up on a grep -f list. For it to only display only the string found i pass this to awk as a variable and loop through the list file using... (5 Replies)
Discussion started by: Cranie
5 Replies

2. Shell Programming and Scripting

Search for string and display those NOT found

In my script I read a input file and search all the files in a directory and it's sub-directories for that string using: find . -type f -print | xargs grep $var1 This just displays all the lines the string was found on. Too much data. What I need is to store in a file one time those... (17 Replies)
Discussion started by: John Rihn
17 Replies

3. Solaris

Can't install Unicode::String due to String.so not found

CPAN.pm: Going to build G/GA/GAAS/Unicode-String-2.09.tar.gz Checking if your kit is complete... Looks good Writing Makefile for Unicode::String cp String.pm blib/lib/Unicode/String.pm cp lib/Unicode/CharName.pm blib/lib/Unicode/CharName.pm /usr/bin/perl /usr/perl5/5.8.4/lib/ExtUtils/xsubpp... (5 Replies)
Discussion started by: PatrickBaer
5 Replies

4. Shell Programming and Scripting

Finding a string with another string is found

finding a string with another string is found EX: abs c/- i want to find /-, then copy abs. i know it's easy use awk, but my problem is the substr syntax. substr($2,2,2) will give me /- but the conflict is /- is not always the second characted of the second string. (11 Replies)
Discussion started by: engr.jay
11 Replies

5. Linux

Find String in FileName and move the String to new File if not found

Hi all, I have a question.. Here is my requirement..I have 500 files in a path say /a/b/c I have some numbers in a file which are comma seperated...and I wanted to check if the numbers are present in the FileName in the path /a/b/c..if the number is there in the file that is fine..but if... (1 Reply)
Discussion started by: us_pokiri
1 Replies

6. Shell Programming and Scripting

grep on string and printing line after until another string has been found

Hello Everyone, I just started scripting this week. I have no background in programming or scripting. I'm working on a script to grep for a variable in a log file Heres what the log file looks like. The x's are all random clutter xxxxxxxxxxxxxxxxxxxxx START: xxxxxxxxxxxx... (7 Replies)
Discussion started by: rxc23816
7 Replies

7. Shell Programming and Scripting

Grep a string and write a value to next line of found string

Hi, I have two variables x and y. i need to find a particular string in a file, a workflow name and then insert the values of x and y into the next lines of the workflow name. basically it is like as below wf_xxxxxx $$a= $$b= $$c= figo $$d=bentley i need to grep the 'wf_xxxx' and then... (6 Replies)
Discussion started by: angel12345
6 Replies

8. UNIX for Dummies Questions & Answers

Append a string on the next line after a pattern string is found

Right now, my code is: s/Secondary Ins./Secondary Ins.\ 1/g It's adding a 1 as soon as it finds Secondary Ins. Primary Ins.: MEDICARE B DMERC Secondary Ins. 1: CONTINENTAL LIFE INS What I really want to achieve is having a 1 added on the next line that contain "Secondary Ins." It... (4 Replies)
Discussion started by: newbeee
4 Replies

9. Shell Programming and Scripting

Modify a file by another file: add new line and variable after string is found

hello, I have problem with writing/adjusting a shell script. I searched forum and unfortunately couldn't write scipt based on the information I found. I never wtire such so it's hard for me and I do need to modify one script immediately. case looks like: 1. 'file' that needs to be modified... (3 Replies)
Discussion started by: bipbip
3 Replies

10. Shell Programming and Scripting

Get 20 lines above string found, and 35 below string

i want to search a log for a string. when that string is found, i want to grab the a set number of lines that came before the string, and a set number of lines that come after the string. so if i search for the word "Error" in the /var/log/messages file, how can I output the 20 lines that came... (4 Replies)
Discussion started by: SkySmart
4 Replies
Info::Layer3::C4000(3pm)				User Contributed Perl Documentation				  Info::Layer3::C4000(3pm)

NAME
SNMP::Info::Layer3::C4000 - SNMP Interface to Cisco Catalyst 4000 Layer 2/3 Switches running IOS AUTHOR
Bill Fenner SYNOPSIS
# Let SNMP::Info determine the correct subclass for you. my $c4000 = new SNMP::Info( AutoSpecify => 1, Debug => 1, # These arguments are passed directly to SNMP::Session DestHost => 'myswitch', Community => 'public', Version => 2 ) or die "Can't connect to DestHost. "; my $class = $c4000->class(); print "SNMP::Info determined this device to fall under subclass : $class "; DESCRIPTION
Abstraction subclass for Cisco Catalyst 4000 Layer 2/3 Switches. For speed or debugging purposes you can call the subclass directly, but not after determining a more specific class using the method above. my $c4000 = new SNMP::Info::Layer3::C4000(...); Inherited Classes SNMP::Info::CiscoVTP SNMP::Info::CDP SNMP::Info::CiscoStats SNMP::Info::CiscoImage SNMP::Info::CiscoPortSecurity SNMP::Info::CiscoConfig SNMP::Info::MAU SNMP::Info::Layer3 Required MIBs Inherited Classes' MIBs See "Required MIBs" in SNMP::Info::CiscoVTP for its own MIB requirements. See "Required MIBs" in SNMP::Info::CDP for its own MIB requirements. See "Required MIBs" in SNMP::Info::CiscoStats for its own MIB requirements. See "Required MIBs" in SNMP::Info::CiscoImage for its own MIB requirements. See "Required MIBs" in SNMP::Info::CiscoPortSecurity for its own MIB requirements. See "Required MIBs" in SNMP::Info::CiscoConfig for its own MIB requirements. See "Required MIBs" in SNMP::Info::MAU for its own MIB requirements. See "Required MIBs" in SNMP::Info::Layer3 for its own MIB requirements. GLOBALS
These are methods that return scalar value from SNMP Overrides $c4000->cisco_comm_indexing() Returns 1. Use vlan indexing. $c4000->fan() Returns fan status Global Methods imported from SNMP::Info::CiscoVTP See documentation in "GLOBALS" in SNMP::Info::CiscoVTP for details. Globals imported from SNMP::Info::CDP See documentation in "GLOBALS" in SNMP::Info::CDP for details. Globals imported from SNMP::Info::CiscoStats See documentation in "GLOBALS" in SNMP::Info::CiscoStats for details. Globals imported from SNMP::Info::CiscoImage See documentation in "GLOBALS" in SNMP::Info::CiscoImage for details. Globals imported from SNMP::Info::CiscoPortSecurity See documentation in "GLOBALS" in SNMP::Info::CiscoPortSecurity for details. Globals imported from SNMP::Info::CiscoConfig See documentation in "GLOBALS" in SNMP::Info::CiscoConfig for details. Globals imported from SNMP::Info::MAU See documentation in "GLOBALS" in SNMP::Info::MAU for details. Globals imported from SNMP::Info::Layer3 See documentation in "GLOBALS" in SNMP::Info::Layer3 for details. TABLE METHODS
These are methods that return tables of information in the form of a reference to a hash. Overrides $c4000->i_duplex() Parses mau_index and mau_link to return the duplex information for interfaces. $c4000->i_duplex_admin() Parses "mac_index","mau_autostat","mau_type_admin" in order to find the admin duplex setting for all the interfaces. Returns either (auto,full,half). $c4000->i_speed_admin() Returns administrative speed for interfaces. Table Methods imported from SNMP::Info::CiscoVTP See documentation in "TABLE METHODS" in SNMP::Info::CiscoVTP for details. Table Methods imported from SNMP::Info::CDP See documentation in "TABLE METHODS" in SNMP::Info::CDP for details. Table Methods imported from SNMP::Info::CiscoStats See documentation in "TABLE METHODS" in SNMP::Info::CiscoStats for details. Table Methods imported from SNMP::Info::CiscoImage See documentation in "TABLE METHODS" in SNMP::Info::CiscoImage for details. Table Methods imported from SNMP::Info::CiscoPortSecurity See documentation in "TABLE METHODS" in SNMP::Info::CiscoPortSecurity for details. Table Methods imported from SNMP::Info::CiscoConfig See documentation in "TABLE METHODS" in SNMP::Info::CiscoConfig for details. Table Methods imported from SNMP::Info::MAU See documentation in "TABLE METHODS" in SNMP::Info::MAU for details. Table Methods imported from SNMP::Info::Layer3 See documentation in "TABLE METHODS" in SNMP::Info::Layer3 for details. perl v5.12.4 2011-09-28 Info::Layer3::C4000(3pm)
All times are GMT -4. The time now is 09:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy