how to remove the assigned value from the string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to remove the assigned value from the string
# 1  
Old 02-04-2009
how to remove the assigned value from the string

Hi
I have the following assignment in my ksh script:
PX_LIST="4119 2390 2294 2776 2897 4099"

Is there any sed/awk command which would allow the to remove certain number from this string. Let's say I need to remove PX=2390 from PX_LIST, so the output after deletion will be"
PX_LIST="4119 2294 2776 2897 4099"

The other lines in the file should not be changed, only value in PX should be removed from the string.

Thanks a lot for any help or advice. -A
# 2  
Old 02-04-2009
Try this:

Code:
sed '/PX_LIST=/ s/2390 //' file

Regards
# 3  
Old 02-04-2009
Franklin, thanks!
It works great for all the numbers except the last one. Is there a way to modify this command so the last number could be deleted as well. Thanks again -A
# 4  
Old 02-04-2009
\< and \> for word boundary markers.

Code:
#!/bin/ksh

cat << EOF > file
PX_LIST="4119 2390 2294 2776 2897 4099"
EOF

search_num=4099

sed "/PX_LIST=/ s/\<$search_num\>//" file

search_num=2294

sed "/PX_LIST=/ s/\<$search_num\>//" file


### to get rid of extra spaces you can go:

search_num=2294
echo `sed "/PX_LIST=/ s/\<$search_num\>//" file`

# 5  
Old 02-04-2009
Something like this?

Code:
sed '/PX_LIST=/ s/2390 //;s/\(.*\) .*/\1"/' file

Regards
# 6  
Old 02-04-2009
Thanks a lot guys!!!! All the best to you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

TCL - quotes inside a string assigned to a var

I know that set line "This is a line." puts whats between " inside the var line. But How do I do the same for set line "This is a line "with quotations" inside the string." (2 Replies)
Discussion started by: popeye
2 Replies

2. Shell Programming and Scripting

Remove not only the duplicate string but also the keyword of the string in Perl

Hi Perl users, I have another problem with text processing in Perl. I have a file below: Linux Unix Linux Windows SUN MACOS SUN SUN HP-AUX I want the result below: Unix Windows SUN MACOS HP-AUX so the duplicate string will be removed and also the keyword of the string on... (2 Replies)
Discussion started by: askari
2 Replies

3. Shell Programming and Scripting

Remove multiple lines from a particular string to particular string

Hi, I have a file containing the DDLs of tables in a schema. From that I need to remove all the lines from a starting string till a specific string. Here is an example. File1.txt ------------- CREATE TABLE "SCHEMA1"."LKP11_TBL_USERS" ( "ID" NUMBER(8,0) NOT NULL ENABLE, "USER_ID"... (3 Replies)
Discussion started by: satyaatcgi
3 Replies

4. Shell Programming and Scripting

Remove first string

Hello, I have below data in a file and i want to remove 0 in front every digit from 1 to 9 16 08 08 16 16 16 16 08 08 16 out put should be 16 8 (2 Replies)
Discussion started by: mirwasim
2 Replies

5. Shell Programming and Scripting

Remove lines between the start string and end string including start and end string Python

Hi, I am trying to remove lines once a string is found till another string is found including the start string and end string. I want to basically grab all the lines starting with color (closing bracket). PS: The line after the closing bracket for color could be anything (currently 'more').... (1 Reply)
Discussion started by: Dabheeruz
1 Replies

6. Shell Programming and Scripting

Remove CR from string

Dear community, I have a very simple question, but I cannot figure out how to solve. I have a simple string containing the carriage return or line feed at the end:# echo $var BLA BLA BLA Now if I want to remove the CR I can use:echo $var|tr -d '\n\r'Because the $var should be reported on a... (7 Replies)
Discussion started by: Lord Spectre
7 Replies

7. Shell Programming and Scripting

Remove String...

Hi, All my source files are having the format of tar.gz . When we have loaded the data in our target output file, we are getting some characters also in our output file like this Actual output is: File1.dat000064400215140000315000000023001164575707100224730ustar|20110506 Expected... (2 Replies)
Discussion started by: suresh01_apk
2 Replies

8. Shell Programming and Scripting

remove characters from string based on occurrence of a string

Hello Folks.. I need your help .. here the example of my problem..i know its easy..i don't all the commands in unix to do this especiallly sed...here my string.. dwc2_dfg_ajja_dfhhj_vw_dec2_dfgh_dwq desired output is.. dwc2_dfg_ajja_dfhhj it's a simple task with tail... (5 Replies)
Discussion started by: victor369
5 Replies

9. Shell Programming and Scripting

Remove path string from file (string contains "/")

This is the way sed -i 's/home/$USER/.config/hello_there//g' /home/$USER/.gnomerc But, as far as I saw you cannot add any "/" in the string you want to remove.... So, what should I do in order to remove this path (which contains "/") ?:confused: (7 Replies)
Discussion started by: hakermania
7 Replies

10. Shell Programming and Scripting

how to remove first two latter of any string

Hi, I have a variable with contain "fl080114". I want only "080114" into an another variable. input: name="fl080114" output: nm="080114" Please help. Thanks in advance. (2 Replies)
Discussion started by: rinku
2 Replies
Login or Register to Ask a Question