Sponsored Content
Top Forums UNIX for Dummies Questions & Answers query on how to search for a line and read 4th word from that line Post 302210535 by krishmaths on Tuesday 1st of July 2008 07:14:24 AM
Old 07-01-2008
One solution:
Code:
awk '/con rome/,/\*/ {print}' file | awk 'NR==3 {print $2}'

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

to get a line above the search word

Hi Everyone. I want to get all the lines above the word error. Note some records dont have error. ex Input Rec # 2384 Client: BGA Rx No: 0735845 Error: (W)Submit Date before Fill Date(SUBMIT-DATE) I want to have the line which starts with... (16 Replies)
Discussion started by: sachin.gangadha
16 Replies

2. Shell Programming and Scripting

Read line by line not word by word

i have this line my,name,is,john stored in a file d.sh and i wish to print the line as string..but im getting word by word...have tried this......... for in $(cat $d.sh); do echo $i done but this is giving me my name is john (6 Replies)
Discussion started by: vadharah
6 Replies

3. Shell Programming and Scripting

How to search word and get the line above it.

Hey all, Could any one help me ... I want to search the word and want the line above it. eg. mytxt.log My name is Jeevan. 240 is my address. My name is Jhon. 390 is my address. -------- i want to search "240" and want output as My name is Jeevan. 240 is my address. ... (7 Replies)
Discussion started by: Jeevan Salunke
7 Replies

4. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies

5. Shell Programming and Scripting

Read last word of nth line

Hi people; i want to read the last word of the 14th line of my file1.txt. Here is the EXACT 14th line of the file. 250 SectorPortnum=3,AuxPortInUngo=2,PortDeviceGroup=1,PortDeviceSet=1,PorDevice=1 20 >>> Set. i have to get the word Set. how can i call it and also how... (3 Replies)
Discussion started by: gc_sw
3 Replies

6. Shell Programming and Scripting

Read last word of the line.

Hi, I need a script to read last word of the line and out put in some temp file. i it can contain any word like: My name is Harry. or My zip code is 24490 or it can be My secret code is 024H I just need last word of the line (Harry, or 2440 or 024H) Thanks for the posts below.... (10 Replies)
Discussion started by: HarryReid
10 Replies

7. Shell Programming and Scripting

While read line query !!!

Folks, I am working on a file which has entries as follows. I am using while read line to generate desired output as follows. filename1: Name : sdt2156157_ID NOS : 4567 NOS : 2348 Name : sdt2156158_ID NOS : 4987 NOS : 2332 while read line... (3 Replies)
Discussion started by: dynamax
3 Replies

8. Shell Programming and Scripting

Read line by line and store a word in array

Hi, I would like to read a file line by line and then store the whole line word by word in array so that I can do specific manipulation on each word. $ cat test.txt hello how are you i am good I would like to have an array created dynamically so that first time , the... (4 Replies)
Discussion started by: ashwin3086
4 Replies

9. Shell Programming and Scripting

Read a File line by line and split into array word by word

Hi All, Hope you guys had a wonderful weekend I have a scenario where in which I have to read a file line by line and check for few words before redirecting to a file I have searched the forum but,either those answers dint work (perhaps because of my wrong under standing of how IFS... (6 Replies)
Discussion started by: Kingcobra
6 Replies

10. Shell Programming and Scripting

Find word in a line and output in which line the word occurs / no. of times it occurred

I have a file: file.txt, which contains the following data in it. This is a file, my name is Karl, what is this process, karl is karl junior, file is a test file, file's name is file.txt My name is not Karl, my name is Karl Joey What is your name? Do you know your name and... (3 Replies)
Discussion started by: anuragpgtgerman
3 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:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy