Remove a value from a string list...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove a value from a string list...
# 1  
Old 06-04-2009
Question Remove a value from a string list...

I have something a bit tricky here and not sure how to go about fixing it.

I am doing a ls on a directory to obtain a list of databases within a directory and assigning it to a string as you can see from below. The problem is there is a folder in there called apache. I do not want this to be included in the string. How can I strip apache from the string Home_Databases? Or better yet even tell it to ignore any folders called apache when doing the ls.

Code:
cd $Dump_Directory
Home_Databases=`ls`
for data_base in $Home_Databases
do
space=`df -bhk $Dump_Directory$data_base/dump | cut -d "y" -f1 | awk '{print$5}'`
Capacity2=${space%?}
Capacity=$space

Thanks for the help. I am really stuck on this one.
# 2  
Old 06-04-2009
Code:
ls | grep -v apache

# 3  
Old 06-04-2009
DUH! I should have known that. Thanks!
# 4  
Old 06-04-2009
Quote:
Originally Posted by LRoberts
I have something a bit tricky here and not sure how to go about fixing it.

I am doing a ls on a directory to obtain a list of databases within a directory and assigning it to a string as you can see from below. The problem is there is a folder in there called apache. I do not want this to be included in the string. How can I strip apache from the string Home_Databases? Or better yet even tell it to ignore any folders called apache when doing the ls.

Code:
cd $Dump_Directory
Home_Databases=`ls`
for data_base in $Home_Databases
do
space=`df -bhk $Dump_Directory$data_base/dump | cut -d "y" -f1 | awk '{print$5}'`
Capacity2=${space%?}
Capacity=$space

Thanks for the help. I am really stuck on this one.
no need `ls`
Code:
for data_base in *

also no need cut when you have awk.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove string perl with first or last word is in a list

Hello, I try to delete all strings if their first or last word is one of this list of words : "the", "i", "in", "there", "this", "with", "on", "we", "that", "of" For example if i have this string in an input file "with me" this string will be removed, Example: input "the european... (2 Replies)
Discussion started by: cyrine
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

Grep string in files and list file names that contain the string

Hi, I have a list of zipped files. I want to grep for a string in all files and get a list of file names that contain the string. But without unzipping them before that, more like using something like gzcat. My OS is: SunOS test 5.10 Generic_142900-13 sun4u sparc SUNW,SPARC-Enterprise (8 Replies)
Discussion started by: apenkov
8 Replies

6. 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

7. UNIX for Dummies Questions & Answers

Creating a column based list from a string list

I have a string containing fields separated by space Example set sr="Fred Ted Joe Peter Paul Jean Chris Tim Tex" and want to display it in a column format, for example to a maximum of a window of 100 characters And hopefully display some thing like Fred Ted Joe ... (3 Replies)
Discussion started by: kristinu
3 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. UNIX for Dummies Questions & Answers

counting a list of string in a list of txt files

Hi there! I have 150 txt files named chunk1, chunk2, ........., chunk150. I have a second file called string.txt with more than 1000 unique strings, house, dog, cat ... I want to know which command I should use to count how many times each string appears in the 150 files. I have tried... (4 Replies)
Discussion started by: Pep Puigvert
4 Replies
Login or Register to Ask a Question