How i can obtain differents data on a single pass?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How i can obtain differents data on a single pass?
# 8  
Old 02-14-2012
Quote:
After more then one hour of search on that follow command:
Code:
sed -n "s/^${1}=//p" $2 2> /dev/null

i don't understand why use the symbol { and } over the first parameter.
You're looking for something too specific.

{ } work when substituting any shell variable in any context shell variables can be substituted in. It's normal syntax, and the safe way to do substitution, because it's less ambiguous. Would $var1_$var2 substitute $var1 or $var1_ ? The latter, to prevent that you'd do ${var1}_${var2}.
This User Gave Thanks to Corona688 For This Post:
# 9  
Old 02-14-2012
I think that now i understand (at least about the { } ).
What about the final 2?
What means?
# 10  
Old 02-14-2012
Quote:
Originally Posted by alexscript
I even make an attempt on test of the sed outside the script but i don't known where i made a mistake:

$ sed -e "s/^{Name}=//p" /usr/share/applications/firefox.desktop
Naturally using -n i don't have output so i used e.
Yes -n causes nothing to print unless a /p is used this ensures only the line with your paramter is printed, to test from command try:

Code:
$ sed -n "s/^Name=//p" /usr/share/applications/firefox.desktop

This User Gave Thanks to Chubler_XL For This Post:
# 11  
Old 02-15-2012
What means the last 2?
If i put 1 a receive an output with empty variable:
Code:
 Entry = "" { Actions = "Exec " }

while if i put 2 or more i receive the correct output.

---------- Post updated at 10:12 AM ---------- Previous update was at 07:33 AM ----------

During the test i find some particular .desktop.

Quote:
[Desktop Entry]
Name=DeaDBeeF
Exec=deadbeef %F
Categories=AudioVideo;Player;GTK;
Icon=deadbeef


[Play Shortcut Group]
Name=Play
Exec=deadbeef --play
TargetEnvironment=Unity

[Pause Shortcut Group]
Name=Pause
Exec=deadbeef --pause
TargetEnvironment=Unity

[Stop Shortcut Group]
Name=Stop
Exec=deadbeef --stop
TargetEnvironment=Unity

[Next Shortcut Group]
Name=Next
Exec=deadbeef --next
TargetEnvironment=Unity

[Prev Shortcut Group]
Name=Prev
Exec=deadbeef --prev
TargetEnvironment=Unity
That produce:
Code:
Entry = "DeaDBeeF
Play
Pause
Stop
Next
Prev" { Actions = "Exec deadbeef %F
deadbeef --play
deadbeef --pause
deadbeef --stop
deadbeef --next
deadbeef --prev" }

How is possible stop the search when the first occurrence is find on the file?
Code:
#!/bin/bash
 
function param_val {
    sed -n "s/^${1}=//p" $2 2> /dev/null
}
 
echo "Dynamic {" 
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=$(param_val Icon $CF)
    categories=$(param_val Categories $CF | cut -d\; -f1)
    echo " Entry = \"$name\" { Actions = \"Exec $executable\" }"
done
echo "}"

So only for the first block?
Quote:
Name=DeaDBeeF
Exec=deadbeef %F
Categories=AudioVideo;Player;GTK;
Icon=deadbeef
Here i read that using the q is possible quit before but i don't known how implement it.


$ sed -n "s/^Name=//p" /usr/share/applications/deadbeef.desktop
Code:
DeaDBeeF
Play
Pause
Stop
Next
Prev


Last edited by alexscript; 02-15-2012 at 05:40 AM..
# 12  
Old 02-15-2012
This function should be closer to what you want - It stops at the first occurance.

Code:
function param_val {
    awk "/^${1}=/{gsub(/^${1}="'/,""); print; exit}' $2
}

eg:
Code:
$ awk '/^Name=/{gsub(/^Name=/,""); print; exit}' /usr/share/applications/deadbeef.desktop
DeaDBeeF

This User Gave Thanks to Chubler_XL For This Post:
# 13  
Old 02-16-2012
Code:
#!/bin/bash

function param_val {
    awk "/^${1}=/{gsub(/^${1}="'/,""); print; exit}' $2
}
 
echo "Dynamic {" 
for CF in `ls -c1 /usr/share/applications/*.desktop`
do
    name=$(param_val Name $CF)

    executable=$(param_val Exec $CF)

    icon=$(param_val Icon $CF)

    categories=$(param_val Categories $CF | awk -F ";" '{print $1}')

    echo " Entry = \"$name\" { Actions = \"Exec $executable\" }"

done
echo "}"

I replace:
categories=$(param_val Categories $CF | cut -d\; -f1)
with:
categories=$(param_val Categories $CF | awk -F ";" '{print $1}')
for remove the dependency with the command line cut.

This is the first release with some minor adjustment.

Thanks for the help. Smilie

Last edited by alexscript; 02-17-2012 at 05:25 AM.. Reason: minor correction
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question