Sponsored Content
Top Forums Shell Programming and Scripting Comma Seperated List of Values Post 100009 by brap45 on Thursday 23rd of February 2006 02:07:52 AM
Old 02-23-2006
Comma Seperated List of Values

Hi,

I have a comma seperated list of values:

export list="red,blue,white,yellow"

Given a value in a variable "look", i want to check whether the value is available in the above list. But the result should be based on exact string match and not part of the string.

I am using following command:
echo $list | grep $look

For Eg:
1. When look="red", the above command returns "red,blue,white,yellow". This is CORRECT as i consider the value is present.

2. When look="green", the above command returns "" (BLANK). This is CORRECT as i consider the value is not present.

3. When look="low", the above command returns "red,blue,white,yellow". This is WRONG as low is not word but part of the 'yellow' word. The result should ideally give me ""(BLANK).

Can anybody help me out to overcome my problem OR is there any better way to check whether a given exact word is present in a list.

TIA

Warm Regards,
Ramesh
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to load comma seperated values file (*.csv) into Oracle table

Hi all I need to input values in a .csv file into my Oracle table running in Unix, I wonder what would be the command to do so... The values are recorded in an excel file and I tried using a formatted text file to do so but failed because one of the field is simply too large to fit in the... (5 Replies)
Discussion started by: handynas
5 Replies

2. UNIX for Advanced & Expert Users

How to load comma seperated values file (*.csv) into Oracle table

Hi all I need to input values in a .csv file into my Oracle table running in Unix, I wonder what would be the command to do so... The values are recorded in an excel file and I tried using a formatted text file to do so but failed because one of the field is simply too large to fit in the... (4 Replies)
Discussion started by: handynas
4 Replies

3. Shell Programming and Scripting

change list to comma seperated items

I have a list of servers in a file called serverlist like this server1 server2 server3 i need to have them (with no trailing comma, the program does not like that) server1,server2,server3 so far i have been using HOSTS=/tmp/serverlist HOSTS=${HOSTS:-$(grep -Ev "^#|^$"... (2 Replies)
Discussion started by: insania
2 Replies

4. UNIX for Dummies Questions & Answers

Search and then concat 4m other file (comma seperated)

My query is now a bit simplified. file1.txt names; ID; value1 ; values N; ABC; 1 ; a18 ; ... CDF; 2 ; b16 ; .. ABC; 1 ; c13 ; ...... EFG; 3 ;d12 ; ... file2.txt ID(Unique);smVals; smVal1; smVal N; 1; ...; ...; ...; 2; ..; ..; ..; 3; ..; ..; ..; ... (1 Reply)
Discussion started by: szchmaltz
1 Replies

5. Shell Programming and Scripting

Removing blank lines from comma seperated and space seperated file.

Hi, I want to remove empty/blank lines from comma seperated and space seperated files Thanks all for help (11 Replies)
Discussion started by: pinnacle
11 Replies

6. Shell Programming and Scripting

perl help for comma seperated output

Hi, how can i make a comma seperated output summary. i attached the sample log file. I have to capture these data in the log file. Arcotid Time Stamp, Username, Success, Failure, Error Code, Error Message In the log snippet the userID can be found in- Code Arcot Native Server:... (3 Replies)
Discussion started by: namishtiwari
3 Replies

7. Shell Programming and Scripting

Script to append a value seperated by comma

I have a file like below. How can I add a new value after moss separated by a comma. This adding script should work in such a way that each time i pass a value it should be added one after the other separated by commas. hru:122: hello:123:john,philip,mary,kp,moss hi:124: bye:125: Can... (7 Replies)
Discussion started by: Tuxidow
7 Replies

8. Shell Programming and Scripting

Passing Comma seperated arguments

Hi How to takes coma seperated arguments and and parsing each argument to varaiable that has used further in the script. (1 Reply)
Discussion started by: Reddy482
1 Replies

9. Shell Programming and Scripting

Convert comma seperated file to line seperated.

Hi, I have data like this. 1,2,3,4 Output required: 1 2 3 4 I am trying to use tr function but getting error. Help is appreciated. (6 Replies)
Discussion started by: pinnacle
6 Replies

10. Shell Programming and Scripting

awk comma seperated value within double quote

Hi, I have a data file separated by comma, data enclosed by "" head file.txt "HD","Sep 13 2016 1:05AM","0001" "DT","273093045","192534" "DT","273097637","192534" .. I want to get the 3rd column value (0001) to be assigned to my variable I tried FILE_VER=`cat file.txt | awk... (2 Replies)
Discussion started by: Prasannag87
2 Replies
ARRAY_SPLICE(3) 							 1							   ARRAY_SPLICE(3)

array_splice - Remove a portion of the array and replace it with something else

SYNOPSIS
array array_splice (array &$input, int $offset, [int $length], [mixed $replacement = array()]) DESCRIPTION
Removes the elements designated by $offset and $length from the $input array, and replaces them with the elements of the $replacement array, if supplied. Note that numeric keys in $input are not preserved. Note If $replacement is not an array, it will be typecast to one (i.e. (array) $parameter). This may result in unexpected behavior when using an object or NULL$replacement. PARAMETERS
o $input - The input array. o $offset - If $offset is positive then the start of removed portion is at that offset from the beginning of the $input array. If $offset is negative then it starts that far from the end of the $input array. o $length - If $length is omitted, removes everything from $offset to the end of the array. If $length is specified and is positive, then that many elements will be removed. If $length is specified and is negative then the end of the removed portion will be that many elements from the end of the array. If $length is specified and is zero, no elements will be removed. Tip: to remove everything from $offset to the end of the array when $replacement is also specified, use count($input) for $length. o $replacement - If $replacement array is specified, then the removed elements are replaced with elements from this array. If $offset and $length are such that nothing is removed, then the elements from the $replacement array are inserted in the place specified by the $offset. Note that keys in replacement array are not preserved. If $replacement is just one element it is not necessary to put array() around it, unless the element is an array itself, an object or NULL. RETURN VALUES
Returns the array consisting of the extracted elements. EXAMPLES
Example #1 array_splice(3) examples <?php $input = array("red", "green", "blue", "yellow"); array_splice($input, 2); // $input is now array("red", "green") $input = array("red", "green", "blue", "yellow"); array_splice($input, 1, -1); // $input is now array("red", "yellow") $input = array("red", "green", "blue", "yellow"); array_splice($input, 1, count($input), "orange"); // $input is now array("red", "orange") $input = array("red", "green", "blue", "yellow"); array_splice($input, -1, 1, array("black", "maroon")); // $input is now array("red", "green", // "blue", "black", "maroon") $input = array("red", "green", "blue", "yellow"); array_splice($input, 3, 0, "purple"); // $input is now array("red", "green", // "blue", "purple", "yellow"); ?> Example #2 array_splice(3) examples The following statements change the values of $input the same way: <?php array_push($input, $x, $y); array_splice($input, count($input), 0, array($x, $y)); array_pop($input); array_splice($input, -1); array_shift($input); array_splice($input, 0, 1); array_unshift($input, $x, $y); array_splice($input, 0, 0, array($x, $y)); $input[$x] = $y; // for arrays where key equals offset array_splice($input, $x, 1, $y); ?> SEE ALSO
array_slice(3), unset(3), array_merge(3). PHP Documentation Group ARRAY_SPLICE(3)
All times are GMT -4. The time now is 02:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy