Sponsored Content
Top Forums Programming Search or find a element inside list python Post 303033248 by Priya Amaresh on Tuesday 2nd of April 2019 06:20:45 AM
Old 04-02-2019
this is python3
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk search for a element in the list of strings

Hi, how do I match a particular element in a list and replace it with blank? awk 'sub///' $FILE list="AL, AK, AZ, AR, CA, CO, CT, DE, FL, GA, HI, ID, IL, IN, IA, KS, KY, LA, ME, MD, MA, MI, MN, MS, MO, MT, NE, NV, NH, NJ, NM, NY, NC, ND, OH, OK, OR, PA, RI, SC, SD, TN, TX, UT, VT, VA, WA,... (2 Replies)
Discussion started by: grossgermany
2 Replies

2. UNIX for Dummies Questions & Answers

script to search patterns inside list of files

>testfile while read x do if then echo $x >> testfile else fi if then echo $x >> testfile else fi done < list_of_files is there any efficient way to search abc.dml and xyz.dml ? (2 Replies)
Discussion started by: dr46014
2 Replies

3. Shell Programming and Scripting

Need to find root element name of XML file

Given this XML: <?xml version="1.0"?> <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd> <cd> <title>Hide your heart</title> ... (2 Replies)
Discussion started by: ricksj
2 Replies

4. Shell Programming and Scripting

Find if XML element has a matching required element

I want to check if every <Part> element has corresponding <Description> in this sample XML. ....<Lot Of XML> <Inv lineNumber="2"> <Item> ... (4 Replies)
Discussion started by: kchinnam
4 Replies

5. Shell Programming and Scripting

awk Search Array Element Return Index

Can you search AWK array elements and return each index value for that element. For example an array named car would have index make and element engine. I want to return all makes with engine size 1.6. Array woulld look like this: BMW 1.6 BMW 2.0 BMW 2.5 AUDI 1.8 AUDI 1.6 ... (11 Replies)
Discussion started by: u20sr
11 Replies

6. Shell Programming and Scripting

Find first n element by matching IDs

Hi All I have a problem that I am not able to resolve. Briefly, I have a file like this: ID_1 10 ID_2 15 ID_3 32 ID_4 45 ID_5 66 ID_6 79 ID_7 88This file is numerically ordered for the 2th column. And another file containing a list of IDs(just one in this example) ID_4What I... (7 Replies)
Discussion started by: giuliangiuseppe
7 Replies

7. Shell Programming and Scripting

sed command inside paramiko python

Hi I am trying to execute a sed command inside paramiko which finds and deletes the particular string from a file But sed command doesnt work inside paramiko python machine=qwe dssh = paramiko.SSHClient() dssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: ... (4 Replies)
Discussion started by: Priya Amaresh
4 Replies

8. Shell Programming and Scripting

Find common values in python list in ordered format

Hello All, There are various codes available to find the intersection between two sets in python. But my case is the following: I want to find the continual common pattern in different lists compared to list1. (i have underlined the longest common patterns in set a and set b) a = 2, 3, 5,... (1 Reply)
Discussion started by: Zam_1234
1 Replies

9. Shell Programming and Scripting

How to insert a CSV within xml element tag using Python?

Hi Team, I have a CSV file which I have to read through and needs to insert the content within an XML file using Python ONLY ( as most of the code base we have in python only). I managed to find the first part, missing how to insert to XML under "specific" tags. cat input.csv... (0 Replies)
Discussion started by: panyam
0 Replies

10. Programming

Create a C source and compile inside Python 1.4.0 to 3.7.0 in Python for ALL? platforms...

Hi all... As you know I like making code backwards compatible for as many platforms as possible. This Python script was in fact dedicated for the AMIGA A1200 using Pythons 1.4.0, 1.5.2, 1.6.0, 2.0.1, and 2.4.6 as that is all we have for varying levels of upgrades from a HDD and 4MB FastRam... (1 Reply)
Discussion started by: wisecracker
1 Replies
SYSTEMD.ENVIRONMENT-GENERATOR(7)			   systemd.environment-generator			  SYSTEMD.ENVIRONMENT-GENERATOR(7)

NAME
systemd.environment-generator - systemd environment file generators SYNOPSIS
/lib/systemd/system-environment-generators/some-generator /usr/lib/systemd/user-environment-generators/some-generator /run/systemd/system-environment-generators/* /etc/systemd/system-environment-generators/* /usr/local/lib/systemd/system-environment-generators/* /lib/systemd/system-environment-generators/* /run/systemd/user-environment-generators/* /etc/systemd/user-environment-generators/* /usr/local/lib/systemd/user-environment-generators/* /usr/lib/systemd/user-environment-generators/* DESCRIPTION
Generators are small executables that live in /lib/systemd/system-environment-generators/ and other directories listed above. systemd(1) will execute those binaries very early at the startup of each manager and at configuration reload time, before running the generators described in systemd.generator(7) and before starting any units. Environment generators can override the environment that the manager exports to services and other processes. Generators are loaded from a set of paths determined during compilation, as listed above. System and user environment generators are loaded from directories with names ending in system-environment-generators/ and user-environment-generators/, respectively. Generators found in directories listed earlier override the ones with the same name in directories lower in the list. A symlink to /dev/null or an empty file can be used to mask a generator, thereby preventing it from running. Please note that the order of the two directories with the highest priority is reversed with respect to the unit load path, and generators in /run overwrite those in /etc. After installing new generators or updating the configuration, systemctl daemon-reload may be executed. This will re-run all generators, updating environment configuration. It will be used for any services that are started subsequently. Environment file generators are executed similarly to unit file generators described in systemd.generator(7), with the following differences: o Generators are executed sequentially in the alphanumerical order of the final component of their name. The output of each generator output is immediately parsed and used to update the environment for generators that run after that. Thus, later generators can use and/or modify the output of earlier generators. o Generators are run by every manager instance, their output can be different for each user. It is recommended to use numerical prefixes for generator names to simplify ordering. EXAMPLES
Example 1. A simple generator that extends an environment variable if a directory exists in the file system # 50-xdg-data-dirs.sh #!/bin/bash # set the default value XDG_DATA_DIRS="${XDG_DATA_DIRS:-/usr/local/share/:/usr/share}" # add a directory if it exists if [[ -d /opt/foo/share ]]; then XDG_DATA_DIRS=/opt/foo/share:${XDG_DATA_DIRS} fi # write our output echo XDG_DATA_DIRS=$XDG_DATA_DIRS Example 2. A more complicated generator which reads existing configuration and mutates one variable # 90-rearrange-path.py #!/usr/bin/env python3 """ Proof-of-concept systemd environment generator that makes sure that bin dirs are always after matching sbin dirs in the path. (Changes /sbin:/bin:/foo/bar to /bin:/sbin:/foo/bar.) This generator shows how to override the configuration possibly created by earlier generators. It would be easier to write in bash, but let's have it in Python just to prove that we can, and to serve as a template for more interesting generators. """ import os import pathlib def rearrange_bin_sbin(path): """Make sure any pair of .../bin, .../sbin directories is in this order >>> rearrange_bin_sbin('/bin:/sbin:/usr/sbin:/usr/bin') '/bin:/sbin:/usr/bin:/usr/sbin' """ items = [pathlib.Path(p) for p in path.split(':')] for i in range(len(items)): if 'sbin' in items[i].parts: ind = items[i].parts.index('sbin') bin = pathlib.Path(*items[i].parts[:ind], 'bin', *items[i].parts[ind+1:]) if bin in items[i+1:]: j = i + 1 + items[i+1:].index(bin) items[i], items[j] = items[j], items[i] return ':'.join(p.as_posix() for p in items) if __name__ == '__main__': path = os.environ['PATH'] # This should be always set. # If it's not, we'll just crash, we is OK too. new = rearrange_bin_sbin(path) if new != path: print('PATH={}'.format(new)) Example 3. Debugging a generator SYSTEMD_LOG_LEVEL=debug VAR_A=something VAR_B="something else" /lib/systemd/system-environment-generators/path-to-generator SEE ALSO
systemd-environment-d-generator(8), systemd.generator(7), systemd(1), systemctl(1) systemd 237 SYSTEMD.ENVIRONMENT-GENERATOR(7)
All times are GMT -4. The time now is 12:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy