Sponsored Content
Top Forums Shell Programming and Scripting Search for a Keyword in file and replace another keyword or add at the end of line Post 302899307 by dashing201 on Monday 28th of April 2014 11:48:16 AM
Old 04-28-2014
Search for a Keyword in file and replace another keyword or add at the end of line

Hi

I want to implement something like this:

if( keyword1 exists)
then
check if(keyword2 exists in the same line)
then replace keyword 2 with New_Keyword
else
Add New_Keyword at the end of line
end if


eg:

Check for Keyword JUNGLE and add/replace VALUES(TIGER,LION):
Here JUNGLE is Keyword1 and VALUES is Keyword2 and VALUES(TIGER,LION) is New_Keyword.

Lines in INPUT File
Code:
JUNGLE Hello WORLD VALUES(DEER,WOLF),
RIVER Hello WORLD,
JUNGLE Hello WORLD,

In Line 1, we can have any values inside ().
Expected OUTPUT File
Code:
JUNGLE Hello WORLD VALUES(TIGER,LION),
RIVER Hello WORLD,
JUNGLE Hello WORLD VALUES(TIGER,LION),

In Line 1, we over write the existing values.
In Line 3, we added values at the end.
In Line 2, no changes required and keyword JUNGLE is missing in the line.

Let me know if more clarity is required.

Last edited by bartus11; 04-28-2014 at 12:57 PM.. Reason: Please use [code][/code] tags instead of [icode].
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to search a keyword within a file using a for loop

hi guys i have a problem here, im trying to stablish a relationship between a text file and an input user for example the script is going to prompt the user for some football team and what the script is going to do is return the colums in which that input is located so far this is what i have ... (6 Replies)
Discussion started by: lucho_1
6 Replies

2. Shell Programming and Scripting

how to search reports with specified keyword in log

Hi, I have a question with sed/awk. When I handle some log files I want to search all reports with specified keyword. For example, in the log below. abcd efg ===start abc e ===end xyz ===start af f ===end nf ga ===start ab ===end (4 Replies)
Discussion started by: danielnpu
4 Replies

3. Shell Programming and Scripting

multiple search keyword in grep

Dear All, I have a file containing info like TID:0903 asdfasldjflsdjf TID:0945 hjhjhkhkhkh TID:2045 hjhjhkhkhkh TID:1945 hjhjhkhkhkh TID:2045 hjhjhkhkhkh I need to show only lines containing TID:0903 asdfasldjflsdjf TID:0945 hjhjhkhkhkh TID:2045 hjhjhkhkhkh TID:2045 hjhjhkhkhkh ... (11 Replies)
Discussion started by: saifurshaon
11 Replies

4. Shell Programming and Scripting

Replace only if the keyword is the first word in every line

How do I replace only if the keyword is at the begining of a line? Code: -- a = “This is a print statement” print a -- What if I want to replace print by #print only in the second line i.e only if the line starts with that keyword. Please help me out. I'm new to SED. -----Post... (5 Replies)
Discussion started by: alexzubin
5 Replies

5. Shell Programming and Scripting

search for keyword in subsequent lines and delete the second line

I have my data something like this I need to search for the keyword yyyy in the susequent lines and if it is present, delete the second line with keyword. In other words, if a keywords is found in two subsequent lines delete the second line. input data: aaaa bbbbb cccc dddd xxxx... (4 Replies)
Discussion started by: rdhanek
4 Replies

6. Shell Programming and Scripting

find keyword from file and search in another file

hi dudes; this is my file.txt:20101228-180436_Down a 1 b 2 ... 20101228-190436_Rollback a 1 40 e 3 20 ... 20101228-180436_Down c 2 f 2 c 1 ... and i have a down.txt:a 1 aa 2 30 bb 1 40 b 2 ab 3 10 c 3 cd 4 50 ac 2 20 c 3 ad 1 0 (2 Replies)
Discussion started by: gc_sw
2 Replies

7. Shell Programming and Scripting

How can i use sed to replace a keyword in an xml file?

Hello Unix gurus! I'm a unix newbie. Can I use sed to replace a keyword in an xml file and convert this keyword with an output of a unix cat command? for example: <test>keyword</test> and temp.txt = hello! I would like to replace "keyword" with the output of "cat temp.txt". I think... (6 Replies)
Discussion started by: 4dirk1
6 Replies

8. Solaris

Keyword search input from a file

Hi, I have a file which got only one column and got some keywords. I have another file where the keywords used in the first file are repeated in the second file. Now I would like to know how many times each keyword from the first file is repeated in the second file. Request your help on... (1 Reply)
Discussion started by: pointers
1 Replies

9. Shell Programming and Scripting

Keyword search/replace for two text files?

What is the best way (bash/awk/sed?) to read in two text files and do a keyword search/replace? file1.txt: San Francisco Los Angeles Seattle Dallas file2.txt: I love Los Angeles. Coming to Dallas was the right choice. San Francisco is fun. Go to Seattle in the summer. ... (3 Replies)
Discussion started by: pxalpine
3 Replies

10. Shell Programming and Scripting

awk to count start and end keyword in a line

Hello fellow awkers and seders: need to figure out a way to ensure a software deployment has completed by checking its trace file in which I can store the deployment results as follows: echo $testvar ===== Summary - Deploy Result - Start ===== ===== Summary - Deploy Result - End =====... (1 Reply)
Discussion started by: ux4me
1 Replies
MPITASK(1)                                                         LAM COMMANDS                                                         MPITASK(1)

NAME
mpitask - Monitor MPI processes under LAM. SYNOPSIS
mpitask [-cdh] [-gps] [nodes] [processes] OPTIONS
-c Print communicator descriptions. See "Communicators". -d Print datatype descriptions. See "Datatypes". -gps Print process information in GPS format. -h Print useful information on this command. The -c and -d options are mutually exclusive. DESCRIPTION
The mpitask command displays information on processes which are using MPI. One line is printed for each reported MPI process. With no processes or nodes explicitly specified on the command line, all MPI processes on all nodes are reported. % mpitask TASK (G/L) FUNCTION PEER|ROOT TAG COMM COUNT DATATYPE 0/0 trivial Ssend 1/1 123 WORLD 64 INT 1/1 trivial Recv 0/0 456 WORLD 64 INT For each process mpitask normally prints the following information: TASK an identification of the process - If the process is currently communicating, a `/' followed by the process's rank within the current communicator is also displayed. The executable name, if available, is also displayed. See "MPI Process Identification". FUNCTION an abbreviated form of the function name if the process is blocked inside an MPI function - Otherwise one of the following execu- tion states is printed: running free to run on the underlying OS paused blocked on lam_kpause(2) stopped stopped by the LAM signal, LAM_SIGARREST - See doom(1). blocked blocked in a LAM function - In general this should be a transitory state. Further information on a LAM process's state can be obtained with state(1). PEER|ROOT the source or destination of a point-to-point communication or the root process of certain collective communications, followed by a '/' and the process's rank within the current communicator - TAG the message tag, if any, which was specified as a parameter to the current MPI function COMM the communicator ID, if any, which was specified as a parameter to the current MPI function - Communicators used in collective calls are displayed with a * suffix. Further information on the communicator may be obtained with the -c option. COUNT the element count, if any, which was specified as a parameter to the current MPI function DATATYPE the element datatype, if any, which was specified as a parameter to the current MPI function - For intrinsic datatypes, a short- ened version of the datatype name is displayed. For derived datatypes, a datatype label is displayed. Further information on the datatype may be obtained with the -d option. MPI Process Identification By default, MPI processes are identified by their rank in MPI_COMM_WORLD. We refer to this rank more concisely as the "global" rank (G). The rank within the currently employed communicator is referred to as the "local" rank (L). Since processes may be dynamically spawned (see MPIL_Spawn(2)) and since multiple concurrent MPI applications are allowed, it is possible for multiple MPI_COMM_WORLD communicators to coexist. In these situations, the global rank is no longer globally unique and the identifi- cation is ambiguous. Thus, LAM provides an alternate way of identifying MPI processes, the GPS (Global Positioning System). A process's GPS consists of the nodeid the process is running on and the process's LAM index on that node. It is displayed in mpitask as the pair nn- ode,iindex. If the -gps option is given then the GPS is substituted for the global rank (G). Communicators If the -c option is given then information is no longer displayed in the horizontal format described above. Instead for each selected process currently using a communicator, the information from the TASK column, described above, is given followed by an expanded description of the communicator. This description includes the size of the communicator group(s) and the global identifiers of all members of the group(s). Datatypes If the -d option is given then information is no longer displayed in the horizontal format described above. Instead for each selected process currently using a communicator, the information from the TASK column, described above, is given followed by the datatype's type map. EXAMPLES
mpitask Display the status of all MPI processes on all nodes. mpitask -c n0 i9 Display the communicator (if any) of process index 9 on node 0. DIAGNOSTICS
If no MPI processes are found, only the title line is displayed. BUGS
Sometimes processes may be shown as blocked inside a non-blocking MPI function. This occurs when the process is blocked inside the MPI function on some internal LAM event. Such states are highly transitory. SEE ALSO
doom(1), libmpi(3), mpirun(1), mpimsg(1), state(1), MPIL_Comm_id(2), MPIL_Type_id(2) LAM 7.1.4 July, 2007 MPITASK(1)
All times are GMT -4. The time now is 10:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy