Shell Script question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script question
# 1  
Old 08-26-2008
Shell Script question

Hello Experts,

I am new at this and need some help. I am looking for a delete command that allows me after I grep for the hostname to delete all the lines between two characters. for example I want to delete the first line all the way up to the } character

host test019 {
hardware ethernet F:F:F:F:F:F;
fixed-address secap1019;
group Servers;
}

Thanks in advance.
# 2  
Old 08-26-2008
Quote:
Originally Posted by ryanique
Hello Experts,

I am new at this and need some help. I am looking for a delete command that allows me after I grep for the hostname to delete all the lines between two characters. for example I want to delete the first line all the way up to the } character

host test019 {
hardware ethernet F:F:F:F:F:F;
fixed-address secap1019;
group Servers;
}
No need for grep:

Code:
sed '/host test019/,/}/d' FILENAME

# 3  
Old 08-26-2008
Thansk cfajohnson.

I tried the code and it did not work..I made a little change to it.. this is what i did..

sed '/host $Hostname/,/}/d' hosts.txt

is this correct?
# 4  
Old 08-26-2008
Quote:
Originally Posted by ryanique
Thansk cfajohnson.

I tried the code and it did not work..I made a little change to it.. this is what i did..

sed '/host $Hostname/,/}/d' hosts.txt

is this correct?

Did it work? If so, it's correct.

But, no, it is not correct. Variables are not expanded inside single quotes.

Code:
sed "/host $Hostname/,/}/d" hosts.txt

# 5  
Old 08-26-2008
No it did not work...Neither is this one working... Is there another command other than sed that can be used?

Thanks
# 6  
Old 08-26-2008
Quote:
Originally Posted by ryanique
No it did not work...Neither is this one working...

What does did not work mean? What did happen?

What is the value of $Hostname?
Is there another command other than sed that can be used?
[/QUOTE]

You could use awk, but if the sed command is not working, then either you are not typing it exactly as shown or you are not describing what you want to do correctly.
# 7  
Old 08-26-2008
Thanks again for your patience...As I said i'm new to this...Let me see if i can explain it a little better...I have a file with a list of host with different hostnames...The function in the script I want to do is delete a given host..So if i wanna delete a host for the host file I enter the host name and delete it...Below is a better look of how my host file looks.
Quote:
host test4 {
hardware ethernet d:D:S:W:W:P;
group Servers;
}
host test5 {
hardware ethernet S:S:S:S:S:S;
group Servers;
}
host test {
hardware ethernet t:T:T:T:T:T;
group Printers;
}
host test2 {
hardware ethernet G:G:G:G:G:G;
group Printers;
}
So what i want to do is basically delete everything for any particular host.

Hope I made is a little clearer.
Thanks

Last edited by jim mcnamara; 08-26-2008 at 02:40 PM.. Reason: added quote labels
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script question

As per code it is getting matched. not sure why it assigning to cols=0. Any inputs please. Input : passed is shell.sh c tablename. if ; then cols=1 table=$2 else cols=0 table=$1 fi (1 Reply)
Discussion started by: ramkumar15
1 Replies

2. Shell Programming and Scripting

Shell script question

Hi all, can you plz check whether the below code is correct & some inputs. I need to read the below file and process it. input : /home/ibm/var.txt urgent not urgent not needed. #!/usr/bin/ksh VAR=/home/ibm/var.txt if ] then (7 Replies)
Discussion started by: ramkumar15
7 Replies

3. Homework & Coursework Questions

question in shell script

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write a Bourne shell script which: • Has one command line argument. • If the command line argument is a... (5 Replies)
Discussion started by: abood1190
5 Replies

4. Homework & Coursework Questions

question on shell script

hiiiiiiiiiiiii,,I found an error on my following script but couldnt find it!!! Can you please help me as soon as possible?! echo "enter a number " read n i=0 first=0 second=1 result=0 prime="true" echo –n " $first $second " while do result=`expr $first + $second` first=$second... (10 Replies)
Discussion started by: moonlips
10 Replies

5. Homework & Coursework Questions

Question on shell script

Hiiiiiiiiiiiii all, Please i want your help fast, the teacher gave us this assignment can u help me to write it? this is the question: Write a shell script to point all prime numbers from the fibonacci series of integer N? using Red hat Os Thanks all and waiting for ur answers... (1 Reply)
Discussion started by: moonlips
1 Replies

6. Shell Programming and Scripting

shell script question

I have script as following.. server_status= some command | grep "Total error: 0" if ; then echo " Server $(hostname) is Down" >>Result fi else echo " Server is OK on $(hostname)" >>Result the if command seems to be not working properly for some... (13 Replies)
Discussion started by: s_linux
13 Replies

7. Shell Programming and Scripting

shell script question

Hi, The contents of my file is below: Name,Location,Degree,Gender,Awards Robert,Philadelphia,Accounting,Male,5 Jane,Chicago,Business,Female,2 Allan,New York,Engineering,Male,6 Tom,Detroit,Computer Science,Male,10 Nancy,Milwaukee,Engineering,Female,4 I want to add a "ID" in the 1st line... (2 Replies)
Discussion started by: xinoo
2 Replies

8. UNIX for Dummies Questions & Answers

Linux Shell Question: how to print the shell script name ?

Suppose I have a script named "sc.sh" in the script how to print out its name "sc.sh"? (3 Replies)
Discussion started by: meili100
3 Replies

9. Shell Programming and Scripting

Shell script question

Hello, i am doing a project for school and i cannot figure out whats wrong with my 2 programs they dont seem to work at all. the first program is called isprime and naturally it checks to see if hte number is prime or not here is my code: #!/usr/bin/bash num=$1 echo you typed if ... (2 Replies)
Discussion started by: jbou1087
2 Replies

10. Shell Programming and Scripting

shell script question

I am using ksh. There is a report having amounts in the following format, 34343.67- 2343.45 23434.89- I want to sum up all the amounts. For this I first need to find out if there is a minus sign at the end and prefix it before summing up. How to achieve this? I thought of using an... (2 Replies)
Discussion started by: tselvanin
2 Replies
Login or Register to Ask a Question