Sponsored Content
Top Forums Shell Programming and Scripting Parsing a name Value pair file Post 302955031 by gandolf989 on Monday 14th of September 2015 09:43:41 AM
Old 09-14-2015
The cut command should give you what you want.
Here is a sample script.

Code:
$ cat mydata.dat
model;location;pollgrp;ifindex;contact;ip;parttype;devtype;part;ifmtu;dwelf
.1.3.6.1.4.1.9.1.1047;abc;PG_CISCO4;3;;10.10.10.1;Interface;Router;GigabitEthernet0/1;1520;
.1.3.6.1.4.1.9.1.2047;;PG_ABCD4;3;LMN;20.20.20.1;;Router;;2345;
.1.3.6.1.4.1.9.1.3047;xyz;;;;;;route;;;xxxx
$ cat runme.sh
#!/bin/bash

MY_HEADER="model;location;pollgrp;ifindex;contact;ip;parttype;devtype;part;ifmtu;dwelf"
for line in `cat mydata.dat`
do
   for i in {1..11}
   do
      THIS_FIELD=`echo $MY_HEADER | cut -d";" -f$i`
      THIS_VALUE=`echo $line      | cut -d";" -f$i`
      printf "%15s" "${THIS_FIELD}: "
      echo "|${THIS_VALUE}|"
   done
   echo " "
done

$ ./runme.sh
        model: |model|
     location: |location|
      pollgrp: |pollgrp|
      ifindex: |ifindex|
      contact: |contact|
           ip: |ip|
     parttype: |parttype|
      devtype: |devtype|
         part: |part|
        ifmtu: |ifmtu|
        dwelf: |dwelf|

        model: |.1.3.6.1.4.1.9.1.1047|
     location: |abc|
      pollgrp: |PG_CISCO4|
      ifindex: |3|
      contact: ||
           ip: |10.10.10.1|
     parttype: |Interface|
      devtype: |Router|
         part: |GigabitEthernet0/1|
        ifmtu: |1520|
        dwelf: ||

        model: |.1.3.6.1.4.1.9.1.2047|
     location: ||
      pollgrp: |PG_ABCD4|
      ifindex: |3|
      contact: |LMN|
           ip: |20.20.20.1|
     parttype: ||
      devtype: |Router|
         part: ||
        ifmtu: |2345|
        dwelf: ||

        model: |.1.3.6.1.4.1.9.1.3047|
     location: |xyz|
      pollgrp: ||
      ifindex: ||
      contact: ||
           ip: ||
     parttype: ||
      devtype: |route|
         part: ||
        ifmtu: ||
        dwelf: |xxxx|

 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

2. Shell Programming and Scripting

Parsing with Name value pair and creating a normalized file

I have url string as follows and I need to parse the name value pair into fields /rows event_id date time payload 1329130951 20120214 22.30.40... (1 Reply)
Discussion started by: smee
1 Replies

3. Shell Programming and Scripting

Sort files as pair file

Hello, I am wondering if there is a way to sort file in directory by pair name : I am looking to get the extension .txt above the .archlike this if possible liste_NATIVE_HINDCAST_PSY1V2R2_R20120314.txt flag.NATIVE_HINDCAST_PSY1V2R2.R20120314.arch... (4 Replies)
Discussion started by: Aswex
4 Replies

4. AIX

How to find pair VIOS?

Hi, I have the scenario, that there 3 VIOS in a Frame in this 2 are in dual VIOS My question is how to find which VIOS are in dual? Also, any vios command to identify the pair member (hostname) of a dual VIOS Regards, Siva (3 Replies)
Discussion started by: ksgnathan
3 Replies

5. Shell Programming and Scripting

Pair wise comparisons

Hi, I have 25 groups and I need to perform all possible pairwise compariosns between them using the formula n(n-1)/2. SO in my case it will be 25(25-1)/2 which is equal to 300 comparisons. my 25 groups are FG1 FG2 FG3 FG4 FG5 NT5E CD44 CD44 CD44 AXL ADAM19 CCDC80 L1CAM L1CAM CD44... (1 Reply)
Discussion started by: Diya123
1 Replies

6. UNIX for Dummies Questions & Answers

Deleting a file with no corresponding pair

Hi, I am working with 2 sets of files (*csv and *asc) and I wanted to delete asc file with no corresponding csv counterpart. I did tried it manually but its been difficult working with a longer list of files. sample files in directory 20120601.csv 20120601_f1.asc 20120603.csv 20120602_f1.asc... (3 Replies)
Discussion started by: ida1215
3 Replies

7. Shell Programming and Scripting

awk name pair values

Team, I have a file like below FILE: NAM1,KEY1,VAL1 NAM1,KEY2,VAL2 NAM1,KEY3,VAL3 NAM2,KEY1,VALA NAM2,KEY2,VALB NAM2,KEY3,VALCOutput: I have to build commands like below <Script> VAL1 VAL2 VAL3 NAME1 <Script> VALA VALB VALC NAME2Can you please help with awk command i can use... (4 Replies)
Discussion started by: mallak
4 Replies

8. Programming

Calculate ratios for each pair in a given file

Hello, My input file looks like this #CHROM POS ID REF ALT QUAL FILTER INFO FORMAT Individual1 Individual2 Individual3 Individual4 Individual5 Individual6 22 10000 ID1 A ... (0 Replies)
Discussion started by: nans
0 Replies
ifindex(8)                                                          FTN mailer                                                          ifindex(8)

NAME
ifindex - Create nodelist index SYNOPSIS
ifindex [-h] [-x verbosity] [-I file] DESCRIPTION
Ifindex creates a nodelist index which is used by ifcico for faster nodelist lookups. Depending on the OPTIONS set when compiling the program, one of 3 different nodelist indices will be generated: a db- a (g)dbm- or a dbz- version. The dbz- type nodelist-index has some advantages (smaller indices and faster index generation) over the other 2 types but is cur- rently only in PRE-ALPHA state - you should also read the README before using this type of nodelist-index. OPTIONS
-h Display a short help message. -x Verbosity Set the debug verbosity. Verbosity may be a number from 0 to 32 to set 'on' bits from 1 to number, or a string of letters where 'a' = bit 1, 'b' = bit 2, etc. up to bit 26. -I File Use the alternate configuration file File. RETURN CODES
0 Successfull 64 command line usage error 65 error reading config file DEBUG VERBOSITY
d lock files f aka matching g outbound directories h call j session handshake k file transfer l filelist m nodelist flags r modem t nodelist index z hydra protocol FILES
$IFLIBDIR/config Runtime configuration file. nodelist.??? A list of nodes in an FTN network. SEE ALSO
ifcico(8), ifinfo(8) ACKNOWLEDGEMENTS
Some ideas taken from Fidogate/RFmail package, written by Teemu Torma and hacked by Martin Junius. Some tcp code taken from JE version, written by Tsuneo Tanaka <ttan@twics.com> 1993, 1994 Eugene Crosser This is free software. You can do what you wish with it as long as this copyright notice is preserved. Manpage and dbz-nodelist-index support by Christof Meerwald <cmeerw@mail.htl.fh-sbg.ac.at> Many thanks to the institute of computer science in Salzburg/Austria and especially to Anton Hofmann <hofmann@wst.edvz.sbg.ac.at> who made further work possible during his lecture. 3.0.cm.alpha-2 May 29, 1997 ifindex(8)
All times are GMT -4. The time now is 01:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy