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(5)							File Formats Manual							stl_key(5)

Name
       stl_key - setld kit manufacturing key file

Description
       The manufacturing key files are used by the software kitting program in producing software distribution packages in format.

       A  key file has a global data section and a subset descriptor section. The sections are separated by a line that is empty except for the %%
       character sequence.

       The global section contains the product level attributes of the product. Comments are permitted in this section. They begin with the number
       sign  (#)  character and end at the next newline character.  Attributes are specified by giving the attribute key, an equal sign (=), and a
       value for the attribute.  There must be no white space surrounding the equals sign (=). There are five attributes that must be present with
       non-null values. These are NAME, CODE, VERS, MI, and ROOT.  An explanation of each of the attributes follows:

	  NAME	    The name of the product. The value for NAME is a string of up to 40 characters.

	  CODE	    The 3-character product code for the product, for example, ULT.

	  VERS	    The 3-digit version code for the product, for example, 040.

	  MI	    The pathname of the master inventory file for the product.

	  ROOT	    A  flag with values of 0 or 1. It is used to determine if a ROOT image checksum should be computed for the product image file.
		    There is no ROOT image in any product other than ULTRIX. Set it to 0.

	  RXMAKE    A flag with values of 0 or 1. Setting it to 0 suppresses the manufacture of subset images for distribution on RX50	diskettes.
		    Omitting this attribute from the key file will cause the program to assume a default value of 1. Digital recommends setting it
		    to 0.

	  COMPRESS  A flag with values of 0 or 1. Setting it to 1 causes the subset images to be compressed  using  the  utility,  thereby  saving
		    space  on the distribution media. Setting it to 0 suppresses compression. Omitting this attribute from the key file will cause
		    the program to assign a default value of 0.

       The subset descriptor section contains one subset descriptor for each subset in the product. There is one subset  descriptor  per  line	in
       this section and comments are not permitted.

       A  subset  descriptor  contains subset-specific attributes in four fields separated by TAB (CTRL/I) characters. A description of each field
       follows:

	  SUBSET    This field contains the name of the subset being described by the descriptor. The subset name is composed of the product code,
		    name and version code.

	  DEPENDENCIES
		    A list of subsets on which the described subset depends. If there are no such subsets, the period character (.) is used.  Mul-
		    tiple subset dependencies are separated by a vertical bar character (|).

	  FLAGS     A subset flags value. This is an integer. Bit 0 is used to mark the subset as irremovable. If bit 0 is set, can  never  delete
		    the  subset. Bit 1 is used to mark the subset as optional, otherwise it is mandatory and must be installed from the media when
		    encountered by

	  DESCRIPTION
		    This is a description of the subset in 40 or fewer characters.  It is used in the menu that presents to a user installing  the
		    software. If spaces are desired in this field, the field must be enclosed in single quotes.

       The subset descriptors must be listed in the order in which the subsets are installed by

Restrictions
       The required attributes and default values are not optimal.

       Comments in the subset descriptor section will cause serious problems when encountered by the program.

       TAB formatting in the subset descriptors is tightly enforced by the program.

Examples
       This is an example key file:
	   #	 ULW400.k -
	   #	      ULTRIX WS V4.0 Server 2/2 (VAX) Mfg Key File
	   #
	   #	 "@(#)ULW400.k	2.2 (ULTRIX) 4/12/89"
	   #
	   #	 000  02-mar-1989    ccb
	   #	 Copy from V2.0 (VAX) Sources
	   #	 Revision update for V4.0

	   #% PRODUCT-LEVEL ATTRIBUTES
	   NAME='ULTRIX Worksystem Software V4.0'
	   CODE=UWS
	   VERS=400
	   MI=ULT400.mi
	   ROOT=0
	   RXMAKE=0
	   COMPRESS=1

	   #% SUBSET-LEVEL ATTRIBUTES
	   %%
	   UWSX11400  ULTINET400     0	  'X11/DECwindows User Environment'
	   UWSFONT400 UWSX11400 0    'X11/DECwindows 75dpi Fonts'
	   UWSFONT15400    .	2    'X11/DECwindows 100dpi Fonts'
	   UWSDECW400 .    2	'Optional DECwindows Applications'
	   UWSXDEV400 ULTPGMR400     2	  'Worksystems Development Software'
	   UWSMAN400  ULTDCMT400     2	  'UWS Manual Pages'

See Also
       kits(1), stl_comp(5), stl_ctrl(5), stl_image(5), setld(8)
       Guide to Preparing Software for Distribution on ULTRIX Systems

																	stl_key(5)
All times are GMT -4. The time now is 01:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy