Sponsored Content
Top Forums Shell Programming and Scripting How i can obtain differents data on a single pass? Post 302598249 by Chubler_XL on Monday 13th of February 2012 11:50:06 PM
Old 02-14-2012
I find myself doing this sort of thing a fair bit and setting up a local param_val() function makes the code much more maintainable/extendable/readable,
and as long as your only processing a few files the overhead can pretty much be ignored, more often than not the file will still be in the cache anyway.


Remember your going to be comming along in a year or two and going "What the $%#$ is this damn awk script doing!"
Code:
#!/bin/bash
 
function param_val {
    sed -n "s/^${1}=//p" $2 2> /dev/null
}
 
 
for i in `ls -c1 /usr/share/applications`
do
    CF=/usr/share/applications/$i
    name=$(param_val Name $CF)
    executable=$(param_val Exec $CF)
    icon=$(parm_val Icon $CF)
    categories=$(param_val Categories $CF | cut -d\; -f1)
done


Last edited by Chubler_XL; 02-14-2012 at 12:57 AM..
This User Gave Thanks to Chubler_XL For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to use cut function to obtain this data out in script?

Hi....can you guys help me out in this script?? Below is a text file script....called Bukom.txt and it contains these: BUKOM 20060101 2.5 2.6 2.7 2.8 2.9 2.3 2.1 BUKOM 20060102 2.4 2.5 2.6 2.7 2.7 2.6 2.4 BUKOM 20060103 2.1 2.3 2.5 2.6 2.7 2.7 2.6 Can you guys help... (2 Replies)
Discussion started by: forevercalz
2 Replies

2. Shell Programming and Scripting

pass curls progress/status data to a file

hello hackers again. please help me out once again. i have a script which executes CURL to fetch a file from the web and instantly outputs the files content to STDOUT. now my question - can i somehow write the progress-status to a file? so that curl acts silently (-s) and only puts... (0 Replies)
Discussion started by: scarfake
0 Replies

3. Web Development

how to pass data in webrick sevelts? please help

Hi all, I am a newbie to servlet programming using webrick... Was wondering how to accept data from a form and do necessary processing.. To start with i wrote a sample servlet that accepts a name and prints "welcome <name>" But I do not know how to take this value from the form into the... (0 Replies)
Discussion started by: wrapster
0 Replies

4. Shell Programming and Scripting

Read Oracle Username password SID from single file and pass it to shell

Dear All I am trying to write one shell which will be running through Cron which contain one SQL query. But I want to draw/fetch the Username password and Instance name (required to loging to the database) from one single file to run that SQL query . Also this file contain details of multiple... (2 Replies)
Discussion started by: jhon
2 Replies

5. Shell Programming and Scripting

How to pass different number of arguments in a single shot

I have one configuration file. The number of lines in the file will vary. I need to pass each line as a parameter to a shell script in a single shot. Ex: Suppose file contains: ou=x,o=z o=y Suppose the shell script name is sample.sh. Then the script should be called like sample.sh ou=x.o=z... (6 Replies)
Discussion started by: saurabhkoar
6 Replies

6. Shell Programming and Scripting

Extract sequences of bytes from binary for differents blocks

Hello to all, I would like to search sequences of bytes inside big binary file. The bin file contains blocks of information, each block begins is estructured as follow: 1- Each block begins with the hex 32 (1 byte) and ends with FF. After the FF of the last block, it follows 33. 2- Next... (59 Replies)
Discussion started by: Ophiuchus
59 Replies

7. Programming

Query SQL get two values differents from the same columns

Hi, I have 2 different values in the same column and two different values in other column Query 1 ins name value 1 Test 12345 1 TestV1 12/10/2014 8 Test 85435 8 TestV1 11/11/2005 9 Test 42232 9 TestV1 19/10/2000 6 Test 54321... (6 Replies)
Discussion started by: faka
6 Replies

8. Shell Programming and Scripting

awk - matching on 2 columns for differents lines

Given this file (I separated them in block to make my explanation clearer): 92157768877;Sof_deme_Fort_Email_am_%yyyy%%mm%%dd%;EMAIL;20/02/2015;1;0;0 92157768877;Sof_trav_Fort_Email_am_%yyyy%%mm%%dd%;EMAIL;20/02/2015;1;0;0 91231838895;Sof_deme_faible_Email_am;EMAIL;26/01/2015;1 0;0... (1 Reply)
Discussion started by: Andy_K
1 Replies

9. Shell Programming and Scripting

Pass some data from csv to xml file using shell/python

Hello gurus, I have a csv file with bunch of datas in each column. (see attached) Now I have an .xml file in the structure of below: ?xml version="1.0" ?> <component id="root" name="root"> <component id="system" name="system"> <param name="number_of_A" value="8"/> ... (5 Replies)
Discussion started by: Zam_1234
5 Replies

10. UNIX for Beginners Questions & Answers

How to pass a single quote to the program?

Dear forum members, My question is simple. I want to pass a single quote (') to be read as belonging as an addition to the letters C1', C2', C3', C4', C5', O1', O2', O3', O4' & O5' to the program voronota query-contacts which would be run through shell script and should print out numerical... (7 Replies)
Discussion started by: Aurimas
7 Replies
All times are GMT -4. The time now is 04:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy