Sponsored Content
Top Forums Shell Programming and Scripting script to parse the properties file Post 302592160 by neutronscott on Monday 23rd of January 2012 03:11:23 AM
Old 01-23-2012
It looks like you are using bash. bash4 has associative arrays, bash3 does not. the bash3 method would save order. here example:

Code:
declare -A array
declare -a keys=()
declare -a vals=()
while IFS='=' read -r key val; do
        [[ $key = '#'* ]] && continue
        array["$key"]="$val"            #bash4
        keys+=("$key"); vals+=("$val")  #bash3
done < "input"

echo "Number of entries: ${#keys[@]} or ${#array[@]}"

# two separate array [bash3]
for ((i = 0; i < ${#keys[@]}; i++)); do
        printf '[%s]=[%s]\n' "${keys[i]}" "${vals[i]}"
done

# associative array [bash4]
for key in "${!array[@]}"; do
        printf '[%s]=[%s]\n' "$key" "${array[$key]}"
done

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How do properties effect script?

Hi, I have noticed that rm -if will perform completely different to rm -fi. Whats the pattern of how I put my options to the script in relation to how it will act. i.e rm -fi treat the remove as interative but rm -if treats it as forced Thansk, Chris. (1 Reply)
Discussion started by: Chiefos
1 Replies

2. UNIX for Dummies Questions & Answers

File properties

Hi , I do have a line in my code as follows: if ] ; then ... else ... fi What does the -z does ? Similarly there is -s in some other part of the code. I guess there are many options like this.. Can anybody please tell what all options are available and what do they mean ? (2 Replies)
Discussion started by: risshanth
2 Replies

3. Shell Programming and Scripting

Help!!! Shell script to parse data file.

I am faced with a :confused: tricky problem to parse a data file ( May not be a tricky problem to the scripting guru's ). Here is what I am faced with. I have a file with multiple rows of data and the rows are not of fixed length. "|" is used as a delimiters for individual columns and each row... (3 Replies)
Discussion started by: yajaykumar
3 Replies

4. UNIX for Advanced & Expert Users

shell script to parse html file

hi all, i have a html file something similar to this. <tr class="evenrow"> <td class="data">added</td><td class="data">xyz@abc.com</td> <td class="data">filename.sql</td><td class="modifications-data">08/25/2009 07:58:40</td><td class="data">Added TK prof script</td> </tr> <tr... (1 Reply)
Discussion started by: sais
1 Replies

5. Shell Programming and Scripting

Reading the Properties File From Shell script

Hi, I am new to the shell script please I need help for following question. I have properties file name called "com.test.properties" I have No of key values in this properties. com.person.name = xyz com.person.age = 55 com.person.address = hello I want read this properties but i... (1 Reply)
Discussion started by: venukjs
1 Replies

6. Shell Programming and Scripting

Script to parse a file faster

My example file is as given below: conn=1 uid=oracle conn=2 uid=db2 conn=3 uid=oracle conn=4 uid=hash conn=5 uid=skher conn=6 uid=oracle conn=7 uid=mpalkar conn=8 uid=anarke conn=1 op=-1 msgId=-1 - fd=104 slot=104 LDAPS connection from 10.10.5.6 to 10.18.6.5 conn=2 op=-1 msgId=-1 -... (7 Replies)
Discussion started by: sags007_99
7 Replies

7. UNIX for Dummies Questions & Answers

Help to parse csv file with shell script

Hello ! I am very aware that this is not the first time this question is asked here, because I have already read a lot of previous answers, but none of them worked, so... As said in the title, I want to read a csv file with a bash script. Here is a sample of the file: ... (4 Replies)
Discussion started by: Grhyll
4 Replies

8. Shell Programming and Scripting

Script to parse bookmarks file

I am using Internet Explorer v10 at work and regularly need to import my personal Firefox bookmarks over. Long story short, I have found the import falling over on any bookmark elements which are over 256 characters. The bookmark file contains bookmarks of this format: <DT><A... (4 Replies)
Discussion started by: ozgadgetguy
4 Replies

9. Shell Programming and Scripting

Script parse file Linux

Hi all, I need help for a script that pulls out a series of numbers from a file (attached file) Basically I need a parse to write me in a variable: 9d424312 Can someone help me? Thank you (2 Replies)
Discussion started by: gianvitolinuxs
2 Replies

10. Homework & Coursework Questions

Script parse file

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Hi all, I need help for a script that pulls out a series of numbers from a file (attached file) Basically I... (1 Reply)
Discussion started by: gianvitolinuxs
1 Replies
XkbAddGeomOverlayKey(3) 					   XKB FUNCTIONS					   XkbAddGeomOverlayKey(3)

NAME
XkbAddGeomOverlayKey - Add a key to an existing overlay row SYNOPSIS
XkbOverlayKeyPtr XkbAddGeomOverlayKey (XkbOverlayPtr overlay, XkbRowPtr row, char *under); ARGUMENTS
- overlay overlay to be updated - row row in overlay to be updated - under primary name of the key to be considered DESCRIPTION
Xkb provides functions to add a single new element to the top-level keyboard geometry. In each case the num_ * fields of the corresponding structure is incremented by 1. These functions do not change sz_* unless there is no more room in the array. Some of these functions fill in the values of the element's structure from the arguments. For other functions, you must explicitly write code to fill the structure's elements. The top-level geometry description includes a list of geometry properties. A geometry property associates an arbitrary string with an equally arbitrary name. Programs that display images of keyboards can use geometry properties as hints, but they are not interpreted by Xkb. No other geometry structures refer to geometry properties. XkbAddGeomOverlayKey adds one key to the row in the overlay. If there is no key named under in the row of the underlying section, XkbAd- dGeomOverlayKey returns NULL. STRUCTURES
typedef struct _XkbOverlayKey { XkbKeyNameRec over; /* name of this overlay key */ XkbKeyNameRec under; /* name of the key under this overlay key */ } XkbOverlayKeyRec,*XkbOverlayKeyPtr; X Version 11 libX11 1.5.0 XkbAddGeomOverlayKey(3)
All times are GMT -4. The time now is 05:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy