Sponsored Content
Top Forums Shell Programming and Scripting Move a line containg "char" above line containing "xchar" Post 302938729 by rex007can on Wednesday 18th of March 2015 03:41:25 PM
Old 03-18-2015
Move a line containg "char" above line containing "xchar"

Okay, so I have a rather large text file and will have to process many more and this will save me hours of work.
I'm not very good at scripting, so bear with me please.

Working on Linux RHEL

I've been able to filter and edit and clean up using sed, but I have a problem with moving lines.

I have a file containing entries like this:
Code:
<tr>
<td>Manufacturer</td>
<td>Type</td>
<td>Model</td>
<td>OID</td>
<td>IF-Usage</td>
<td>Environment</td>
<td>CPU/MEM</td>
</tr>
<tr>
<td>[[Cisco]]</td>
<td>.1.3.6.1.4.1.9.1.1249 </td>
TYPE            = Router
VENDOR          = Cisco
MODEL           = 892F
CERTIFICATION   = CERTIFIED
CONT = Cisco-Router-Entity
NEIGHBOR = Cisco-Cdp
HEALTH = Cisco-Router

For each occurence in the file (literally thousands), I need to move the line "TYPE = Router"
Below the line "<td>[[Cisco]]</td>"

After that I'll need to move other variables around and convert everything to html tables, but that I can do already.
Because I will reuse the command for the other variables in the text, it would be better to do it using matching char rather than just counting lines.

Any ideas?

Last edited by vgersh99; 03-18-2015 at 04:54 PM.. Reason: code tags, please!
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

2. Shell Programming and Scripting

How to remove "New line characters" and "spaces" at a time

Dear friends, following is the output of a script from which I want to remove spaces and new-line characters. Example:- Line1 abcdefghijklmnopqrstuvwxyz Line2 mnopqrstuvwxyzabcdefghijkl Line3 opqrstuvwxyzabcdefdefg Here in above example, at every starting line there is a “tab” &... (4 Replies)
Discussion started by: anushree.a
4 Replies

3. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

4. Shell Programming and Scripting

AWK for multiple line records RS="^" FS="#"

I have to pull multiple line records with ^ as the record separator(RS)... # should be my field separator (FS)... Sample record is: ^-60#ORA-00060: deadlock detected while waiting for resource ORA-00001: unique constraint (SARADM.TCKNUM_PK) violated#PROC:AVAILABLE_FOR_GETNXTTIC#02/27/2012... (7 Replies)
Discussion started by: Vidhyaprakash
7 Replies

5. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

6. Shell Programming and Scripting

Find "*.c" and "Makefile" and then delete them with one line

find "*.c" and "Makefile" and then delete them with one line (3 Replies)
Discussion started by: yanglei_fage
3 Replies

7. Shell Programming and Scripting

Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml"

Dear Ladies & Gents, I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out: for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies

8. Shell Programming and Scripting

Failure: if grep "$Var" "$line" inside while read line loop

Hi everybody, I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o My code: #!/bin/sh set -e set -u export IFS= optl="Optl" LOCSTORCLI="/opt/lsi/storcli/storcli" ($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies

9. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies
Info::CiscoStats(3pm)					User Contributed Perl Documentation				     Info::CiscoStats(3pm)

NAME
SNMP::Info::CiscoStats - Perl5 Interface to CPU and Memory stats for Cisco Devices AUTHOR
Eric Miller, Max Baker, Sam Stickland SYNOPSIS
# Let SNMP::Info determine the correct subclass for you. my $ciscostats = new SNMP::Info( AutoSpecify => 1, Debug => 1, # These arguments are passed directly on to SNMP::Session DestHost => 'myswitch', Community => 'public', Version => 2 ) or die "Can't connect to DestHost. "; my $class = $ciscostats->class(); print "SNMP::Info determined this device to fall under subclass : $class "; DESCRIPTION
SNMP::Info::CiscoStats is a subclass of SNMP::Info that provides cpu, memory, os and version information about Cisco Devices. Use or create in a subclass of SNMP::Info. Do not use directly. Inherited Classes None. Required MIBs CISCO-PRODUCTS-MIB CISCO-PROCESS-MIB CISCO-MEMORY-POOL-MIB SNMPv2-MIB OLD-CISCO-SYSTEM-MIB CISCO-STACK-MIB CISCO-ENTITY-VENDORTYPE-OID-MIB CISCO-FLASH-MIB ENTITY-MIB MIBs can be found at ftp://ftp.cisco.com/pub/mibs/v2/v2.tar.gz GLOBALS
$ciscostats->cpu() Returns ios_cpu() or cat_cpu(), whichever is available. $ciscostats->cpu_1min() Returns ios_cpu_1min() or cat_cpu1min(), whichever is available. $ciscostats->cpu_5min() Returns ios_cpu_5min() or cat_cpu5min(), whichever is available. $ciscostats->mem_total() Returns mem_free() + mem_used() $ciscostats->vendor() 'cisco' $ciscostats->os() Tries to parse if device is running IOS or CatOS from description() Available values : pix Cisco PIX asa Cisco ASA fwsm Single-mode FWSM fwsm-admin Admin context of multi-context FWSM fwsm-context Standard context of multi-context FWSM ace-admin Admin context of ACE module ace-context Standard context of ACE module (NB: No OS version detection is available, but will be the same as it's 'ace admin') css Cisco Content Switch css-sca Cisco Content Switch Secure Content Acceleration $ciscostats->os_ver() Tries to parse device operating system version from description() $ciscostats->os_bin() Tries to parse ROMMON version from rom_id() string $ciscostats->ios_cpu() Current CPU usage in percent. 1.3.6.1.4.1.9.2.1.56.0 = "OLD-CISCO-CPU-MIB:avgBusyPer" $ciscostats->ios_cpu_1min() Average CPU Usage in percent over the last minute. 1.3.6.1.4.1.9.2.1.57.0 $ciscostats->ios_cpu_5min() Average CPU Usage in percent over the last 5 minutes. 1.3.6.1.4.1.9.2.1.58.0 $ciscostats->cat_cpu() Current CPU usage in percent. "CISCO-PROCESS-MIB::cpmCPUTotal5sec.9" $ciscostats->cat_cpu_1min() Average CPU Usage in percent over the last minute. "CISCO-PROCESS-MIB::cpmCPUTotal1min.9" $ciscostats->cat_cpu_5min() Average CPU Usage in percent over the last 5 minutes. "CISCO-PROCESS-MIB::cpmCPUTotal5min.9" $ciscostats->mem_free() Main DRAM free of the device in bytes. "CISCO-MEMORY-POOL-MIB::ciscoMemoryPoolFree" $ciscostats->mem_used() Main DRAM used of the device in bytes. "CISCO-MEMORY-POOL-MIB::ciscoMemoryPoolUsed" $ciscostats->mem_total() Main DRAM of the device in bytes. "CISCO-MEMORY-POOL-MIB::ciscoMemoryPoolFree" + "CISCO-MEMORY-POOL-MIB::ciscoMemoryPoolUsed" $ciscostats->flashmem_total() Flash memory of the device in bytes. "CISCO-FLASH-MIB::ciscoFlashDeviceSize" TABLE METHODS
Cisco Memory Pool Table ("ciscoMemoryPoolTable") $ciscostats->cisco_mem_free() The number of bytes from the memory pool that are currently unused on the managed device. ("ciscoMemoryPoolFree") $ciscostats->cisco_mem_used() The number of bytes from the memory pool that are currently in use by applications on the managed device. ("ciscoMemoryPoolUsed") Cisco Flash Device Table ("ciscoFlashDeviceTable") $ciscostats->cisco_flash_size() Total size of the Flash device. For a removable device, the size will be zero if the device has been removed. ("ciscoFlashDeviceSize") perl v5.12.4 2011-09-28 Info::CiscoStats(3pm)
All times are GMT -4. The time now is 04:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy