I have a networking class that allows you to export your activity log. something like this

switch(config)# int f0/1
switch(config-line)# ip address 192.168..
*configured on 12.6.2017*

if the '#' and text before it is removed and the confirmation text lines (or other response text) so it looks like

int f0/1
ip address 192.168..

I can paste it into another (or the same switch) as a configurations file. it will apply all arguments one line at a time and configure accordingly.

I'd like an app or script to search log files against a template/"list of expressions" to delete the hashtags and prior text on all lines, while keeping the text after the hashtag unaltered. it also be useful if it could remove lines that either don't have hashtags on the first pass or contain certain characters like "!"

ideas? anyone...

 sed -n -e '/[!Qq]/d' -e 's/.*#//p'

will print the parts of lines that follow a #, ignoring lines that don’t contain a # or that do contain a !, Q or q.

The -n tells sed not to print lines except when explicitly told to do so.  The /[!Qq]/d tells it to delete lines containing any of the characters between the [ and the ] (so edit that list to whatever characters you want to reject); i.e., remove them from further consideration.  The s/.*#//p searches for a string of characters ending with #, deletes it, and prints the line.  Lines not containing # will fail this step and so will not be printed.


Notepad++ (Windows) has the ability to record text replacements as macros, as well as use regular expressions for those replacements (though you obviously don't have to). In the simplest case, you would simply start recording the macro, highlight the text to replace e.g. switch(config)#, Replace All with a blank replacement field and stop recording. The macro could then be saved with a custom name for replay later. The nice thing about this is that either single or multiple steps can be recorded (so multiple sequential replacements can be recorded individually or in one macro as needed).

As far as actual scripting, Python would likely be a relatively simple cross-platform solution (assuming it was worth it to you to develop a custom script for your task). A text file could contain items to replace or other instructions (your "template"). Python has fairly robust string tools which would arguably be a good fit for this kind of job.


In CudaText editor (free, cross-platform) you can do it via plugin Extract Strings. Install this plugin via AddonManager, then call "Plugins - Extract Strings". In its dialog, enter regex to find text after #:


Plugin will show found hashtags, you can put them into new empty tab.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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