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 302900173 by dashing201 on Monday 5th of May 2014 09:22:35 AM
Old 05-05-2014
Hi
When I am running the below code I m not getting the desired output.

Code:
awk '$0 ~ /$key1/ {if($0 ~ /COMPRESS/) {sub("COMPRESS.*",$key2)} else {sub("$",$key2) }}1' FILENAME.txt

However if I am hardcoding the variable values it is giving desired output.
Code:
 awk '$0 ~ /HELLO/ {if($0 ~ /COMPRESS/) {sub("COMPRESS.*",HI)} else {sub("$",HI) }}1' FILENAME.txt

Any way by which i can use variables here.
 

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
stl_key(4)						     Kernel Interfaces Manual							stl_key(4)

NAME
stl_key - setld kit manufacturing key files DESCRIPTION
Each software product that is distributed as subsets for the setld(8) command has an associated key file. The key file's name consists of the product's unique 3-letter name and a 3-digit version number with the string .k for a suffix. The key file is used by the software kit- ting program kits(1) in producing software distribution packages. A key file has a global data section and a subset descriptor section. The sections are separated by a line containing only two percent signs (%%). The global section specifies the product-level attributes of the product. In this section, lines that begin with number signs (#) are com- ments and are ignored by the kits utility. Attributes are specified as name/value pairs separated by equals signs (=). There must be no white space surrounding the equals sign. There are four mandatory attributes and two optional attributes. Attributes must have non-null values. The attributes are: NAME Mandatory. Specifies the name of the product. The value for NAME is a text string of up to 40 characters. If the string con- tains blank spaces, it must be enclosed in apostrophes (''). CODE Mandatory. Specifies the 3-character product code for the product, for example, OAT. VERS Mandatory. Specifies the 3-digit version code for the product, for example, 100. MI Mandatory. Specifies the pathname of the master inventory file for the product. ROOT Optional. A single-digit integer that is set to 1 if the product is the base operating system. In all other cases, this flag must be a zero (0). If missing, this attribute defaults to zero. COMPRESS Optional. A single-digit integer that is set to 1 to create compressed subset files using the compress(1) utility, thereby sav- ing space on the distribution media. To suppress compression, this attribute is a zero (0). If missing, this attribute defaults to zero. The subset descriptor section contains one subset descriptor line for each subset in the product. Comments are not permitted in this sec- tion. A subset descriptor contains subset-specific attributes in four fields separated by TAB characters. These fields are: Subset name A character string up to 15 characters in length, composed of the 3-letter product code (for example, OAT), a mnemonic iden- tifying the subset (for example, DCB), and the 3-digit version code (for example, 100). All letters in the subset name must be uppercase. Reserved This field must be a single period. Flags A 16-bit unsigned integer Bit 0 is the ``sticky bit,'' indicating when set that the subset cannot be removed. Bit 1 indicates when set that the subset is optional. Bits 2 to 7 are reserved. Bits 8 to 15 are undefined. Description A short description of the subset, delimited by single quotation marks (''); for example, 'Document Building Tools' The subset descriptors must be listed in the order in which the subsets are to be installed by setld. RESTRICTIONS
Comments in the subset descriptor section will cause serious problems when encountered by the kits program. TAB formatting in the subset descriptors is tightly enforced by the kits program. EXAMPLES
The following example illustrates the key file for a hypothetical product kit: # Key file for the Orpheus Document Building Tools kit # # Product-level attributes. # NAME='Orpheus Authoring Tools' CODE=OAT VERS=100 MI=OAT00.mi ROOT=0 COMPRESS=1 # # Subset def- initions follow. # %% OATDCB100 . 0 'Document Building Tools' OATDCBDOC100 . 2 'Document Tools Documenta- tion' RELATED INFORMATION
Commands: kits(1), setld(8) Files: stl_comp(4), stl_ctrl(4), stl_image(4), stl_mi(4) Documents: Guide to Preparing Product Kits delim off stl_key(4)
All times are GMT -4. The time now is 11:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy