I have a file.dev that contains the following:
1 DEVICES {
2 GLOBAL-CONFIG {
3 framerate = "20000";
4 subframes = "0";
5 max_consec_timeouts = "10";
6 max_total_timeouts = "1000";
7 schedmode = "Standard";
8 clustermode = "Standard";
9 }
10 IO-DEVICES {
11 }
12 COMPUTING-DEVICES {
13 RT_WORKSTATION FDT-C-XM-0120 = {
14 hostname = "FDT-C-XM-0120";
15 ipaddress = "fdt-c-XM-0120.fdtel.exter";
16 DISPLAYS {
17 main = "FDT-C-XM-0120:0.0";
18 }
19 SCHEDPARAM {
20 active = "0";
21 framerate = "20000";
22 subframes = "0";
23 max_consec_timeouts = "10";
24 max_total_timeouts = "1000";
25 }
26 }
27
28 RT_HOST fdt-c-agx-0008 = {
29 hostname = "fdt-c-agx-0008";
30 ipaddress = "fdt-c-agx-0008";
31 SCHEDPARAM {
32 active = "0";
33 framerate = "20000";
34 subframes = "0";
35 max_consec_timeouts = "10";
36 max_total_timeouts = "1000";
37 }
38 }
39
40 # RT_HOST fdt-c-agx-0003 = {
41 # hostname = "fdt-c-agx-0003";
42 # ipaddress = "fdt-c-agx-0003.fdtel.exter";
43 # SCHEDPARAM {
44 # active = "0";
45 # framerate = "20000";
46 # subframes = "0";
47 # max_consec_timeouts = "10";
48 # max_total_timeouts = "1000";
49 # }
50 # }
51 }
52 }
this file is located in a the directory C:/TechSAT/ADS2/config/file.dev
As you can see there are three entry for the variable hostname (line 14, 29 and 41) .
What i'm tying to do is to wrtie a bash script that find only the first entry (line 14) and save its value FDT-C-XM-0120 in a variable like $hostnameValue = FDT-C-XM-0120 for test purposes.
I actually found a semi-working solution like:
var=$(grep -r 'hostname' C:/TechSAT/ADS2/config/devices.dev)
However, this prints all matches like
hostname = "FDT-C-VM-0120";
hostname = "fdt-c-agx-0008";
# hostname = "fdt-c-agx-0003";
and in my case the var must contain the value of the first match which is FDT-C-XM-0120
Thanks in advance
hostname = "FDT-C-VM-0120"with the spaces before and i just want the valueFDT-C-VM-0120var1=$(grep -r 'hostname' -m1 C:/TechSAT/ADS2/config/devices.dev)and as already said the output is the whole line