Sponsored Content
Top Forums Shell Programming and Scripting Script to check a file and replace some of the contents Post 302300043 by Franklin52 on Monday 23rd of March 2009 04:38:37 AM
Old 03-23-2009
Code:
awk -v n="2" -v var="dog" '$2 == n {print;getline;sub("elephant","dog")}1' file

Regards
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace contents of a file

Hi, I want to replace the contents of a file.I tried using : sed 's/01514581/01514582/' $p where 01514581 is the original value 01514582 is the replaced value $p is the file name (captured in a variable).. The output does not recognise $p If you give : sed... (2 Replies)
Discussion started by: shiroh_1982
2 Replies

2. Shell Programming and Scripting

How to replace specific contents in a file?

From the existing file, I need to replace specific contents possibly with var every time when the user changes the var. e.g the contents in the file file.txt is 'My name is $n and I am $y years old' and every time user changed the var outside the file, the contents of the file should be created... (4 Replies)
Discussion started by: Emilywu
4 Replies

3. Shell Programming and Scripting

script to grep a pattern from file compare contents with another file and replace

Hi All, Need help on this I have 2 files one file file1 which has several entries as : define service{ hostgroup_name !host1,!host5,!host6,.* service_description check_nrpe } define service{ hostgroup_name !host2,!host4,!host6,.* service_description check_opt } another... (2 Replies)
Discussion started by: namitai
2 Replies

4. Shell Programming and Scripting

unzip a file then further check contents inside it

Dear all I need to unzip a file then further it has many folders to perform tak inside each folder. What Task I need to perform I'm able to do it but once I unzip a folder then I'm not able to do cd folder/ into it. I have written following code for it for i in $( ls | grep Run_20111016 ) do... (2 Replies)
Discussion started by: Bhalinder
2 Replies

5. Shell Programming and Scripting

Replace partial contents of file with contents read from other file

Hi, I am facing issue while reading data from a file in UNIX. my requirement is to compare two files and for the text pattern matching in the 1st file, replace the contents in second file by the contents of first file from start to the end and write the contents to thrid file. i am able to... (2 Replies)
Discussion started by: seeki
2 Replies

6. Shell Programming and Scripting

Replace file contents from another

Hi Friends, I have a file1 with 5 columns a b c d e f g h i j I have file2 with 3 columns 1 2 3 4 5 6 I want to replace 3rd 4th and 5th columns in file1 with file2 contents, so the output would be a b 1 2 3 f g 4 5 6 Thanks (6 Replies)
Discussion started by: jacobs.smith
6 Replies

7. Shell Programming and Scripting

Shell script to find and replace contents of files in directory

Hi all This is my first post. Please bear with me with all my mistakes. I started learning shell since couple of days now and this might be quite basic for all, i want to search for files in a directory containing specific string and replace it with new string. The code i wrote is quite bulky... (2 Replies)
Discussion started by: theprogrammer
2 Replies

8. Shell Programming and Scripting

Replace Contents from One file into another

Hi Friends, I have two input files cat input1 chr1 100 200 chr1 200 300 chr2 300 400 cat input2 chr1 hello monday 10 20 . - . sometext chr1 hello monday 20 30 . - . sometext chr2 hello monday 30 40 . - . sometext Now, I want to replace $1, $4 and $5 of input2 with $1, $2 and... (1 Reply)
Discussion started by: jacobs.smith
1 Replies

9. UNIX for Dummies Questions & Answers

How To Replace Contents in a File?

How can i replace the contents in a particular line of a file. <FOLDERMAP SOURCEFOLDERNAME="FFCB-2012" SOURCEREPOSITORYNAME="Repo_DEV" TARGETFOLDERNAME="TEST" TARGETREPOSITORYNAME="Dev_Repo"/> For Example I want to replace the SOURCEREPOSITORYNAME="Repo_DEV" to... (3 Replies)
Discussion started by: Ariean
3 Replies

10. Shell Programming and Scripting

Replace contents of a file

Hello, I need help to replace a value by a new one. I've got a script, that will get directory size in ko, then write the size value return in a log file : The patch is given in crontab, and use with $1 in the script. I am looking for help to replace, after: the old value without to... (6 Replies)
Discussion started by: Aswex
6 Replies
ns_set(3aolserver)					    AOLserver Built-In Commands 					ns_set(3aolserver)

__________________________________________________________________________________________________________________________________________________

NAME
ns_set - commands SYNOPSIS
Manipulate sets of key-value pairs. SYNTAX
ns_set copy ?-persist? setId ns_set cput setId key value ns_set create ?-persist? name ns_set delete setId fieldNumber ns_set delkey setId key ns_set find setId key ns_set free setId ns_set get setId key ns_set icput setId key value ns_set idelkey setId key ns_set ifind setId key ns_set iget setId key ns_set isnull setId fieldNumber ns_set iunique setId key ns_set key setId fieldNumber ns_set merge high low ns_set move to from ns_set name setId ns_set new ?-persist? name ns_set print setId ns_set put setId key value ns_set size setId ns_set split ?-persist? setId ?splitChar? ns_set truncate setId size ns_set unique setId key ns_set update setId key value ns_set value setId fieldNumber _________________________________________________________________ DESCRIPTION
ns_set copy Returns a new set that has the same name and key value pairs as the passed-in set (setId). If -persist is specified, the new set will persist even after the current transaction ends, and you can free it later with ns_set free. If -persist is not specified, the new set is automatically freed when the transaction ends. ns_set cput appends a new field to the set with key key and value value if the field does not already exist in the set. The field number of the new field is returned. ns_set create (which is the same as ns_set new) allocates memory for a new set and returns the ID for the new set. If -persist is specified, the new set will persist even after the current transaction ends, and you can free it later with ns_set free. If -persist is not speci- fied, the new set is automatically freed when the transaction ends. ns_set delete deletes the field in the set at field number fieldNumber. ns_set delkey removes the first field in the set whose key is key. Note that there could be multiple fields in the set with this key; this command only removes the first occurrence. ns_set find returns the index of the first field in the specified set whose key name matches the specified key. Zero(0) is the index of the first field. If no matching fields are found, ns_set find returns -1. ns_set free frees the specified set. Sets must be explicitly freed with ns_set free if the -persist option was used when creating the set. Oth- erwise, sets are automatically freed when the transaction ends. ns_set get returns the first value associated with the passed-in key. If the key is invalid, an empty string is returned. ns_set icput is the case-insensitive counterpart of ns_set cput. ns_set idelkey is the case-insensitive counterpart of ns_set delkey. ns_set ifind is the case-insensitive counterpart of ns_set find. ns_set iget is the case-insensitive counterpart of ns_set get. ns_set isnull returns 1 if the value of the field specified by fieldNumber is null and 0 if it is not. Note that an empty string is not the same as a null. ns_set isnull will return 0 for an empty string. ns_set iunique returns 1 if the specified key is unique in the specified set and 0 if it is not. The test for uniqueness is performed case-insensi- tively. ns_set unique is the case-sensitive version of this function. For example, a client could send multiple "Accept:" headers which would end up in the header set for the connection. ns_set iunique would return 0 for the "Accept:" key, because there are multiple fields with the key "Accept:". ns_set key extracts the key of the set at field number fieldNumber. This command is useful when looping through all the key-value pairs in the set. ns_set merge merges two sets. Any fields in the low set are appended to the high set if a field with the same key name does not already exist in the high set. ns_set move moves all fields from the from set to the end of the to set, leaving the from set a valid, empty set. ns_set name returns the name of the set. ns_set new (which is the same as ns_set create) allocates memory for a new set and returns the ID for the new set. If -persist is specified, the new set will persist even after the current transaction ends, and you can free it later with ns_set free. If -persist is not specified, the new set is automatically freed when the transaction ends. ns_set print prints the specified set to stderr. ns_set put appends a new field to the set with key key and value value. Note that the field is appended so if a previous field has the same key as the new field, the previous field is returned by ns_set get command. The field number of the new field is returned. ns_set size returns the number of key-value pairs in the set. ns_set split splits one set into multiple sets based on the splitChar as described below and returns a Tcl list of the newly-allocated sets. It assumes that the keys in the specified set (setId) contain a specific character (splitChar) that can be used to separate the name of a new set and the key in the new set. The default splitChar is a period (.). For example, if two fields in the original set have "dog.food" and "cat.food" as their key names and "Yummy dog food!" and "Yummy cat food!" as their values, ns_set split would return two new sets named "dog" and "cat". The dog set would have a single field whose key is "food" and whose value is "Yummy dog food!". The cat set would have a single field whose key is "food" and whose value is "Yummy cat food!". ns_set truncate reduces the set to the first size key-value pairs and frees the memory for the rest of the key-value pairs that may have been in the set. ns_set unique returns 1 if the specified key is unique in the specified set and 0 if it is not. The test for uniqueness is performed case-sensi- tively. ns_set iunique is the case-insensitive version of this function. ns_set update updates the first field in the specified set whose key is key and replaces its value with value. ns_set update is equivalent to ns_set delkey followed by ns_set put. ns_set value extracts the value of the set at field number fieldNumber. This command is useful when looping through all the key-value pairs in the set. NOTES
The fields in the set are ordered by number. The field numbers range from 0 to one less than the total number of fields. For example, if you have a set with 5 fields, you would use "ns_set key $setid 4" to extract the key of the last field in the set. KEYWORDS
key value AOLserver 4.0 ns_set(3aolserver)
All times are GMT -4. The time now is 02:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy