Add NA When String is not found


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add NA When String is not found
# 8  
Old 10-01-2018
But it all sounds so good in my head when I am typing it out! lol

I am truly sorry.

I am getting information from a cisco switch or router and the format of the output is different depending on the type of device connected. In some cases a match will be made and the field will be returned in other cases it doesnt exist and I would like NA to be printed in its place. This will keep all fields in the output file uniform which is key for the excel import that needs to occur. What is happening is some of the devices wont return a match for the " /VLAN:/" field. Well when this happens, it shifts everything in the output one column to the left.

Does that help to clarify? Im truly not trying to be cryptic but apparently not intelligent enough to properly communicate my problem. Thanks for your help, I do appreciate it
# 9  
Old 10-04-2018
I don't have a Cisco switch or router handy to attempt to see what log output they produce.

I assume that the sample input you showed us in post #4 is not the contents of a switch or router log, but something that you have created by processing the log files to try to get data in the format that you want.

Please show us small samples of the data that would be found in your switch log file and the date that would be found in your router log file and explain the format of both of those.

Then explain the format of the output you hope to produce.

Then show us the output that you hope to produce by processing those two sample log files.
# 10  
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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question