Script that takes IP address as an Input and deletes 7 lines
I have a flat file that contains a list of IP address following 6 additional lines.
I would like to get a help in the following. a shell script that would take ip address or list of ip addresses as input, search one by one the ip address in the file and as soon as it find the exact match it deletes 7 lines including the line that has the ip address. it should then save the file
for example lets say we want to find 166.1.1.3 , the script should be able to find 166.1.1.3 and delete 7 lines including 166.1.1.3.
File contents shown below
Last edited by Scott; 04-25-2014 at 06:33 PM..
Reason: Code tags
1. There must be a semicolon between statements within a block (if not on separate lines).
2. In Solaris you better use /usr/xpg4/bin/awk or nawk.
Best practice is to define PATH at the beginning of the script .
3. $ipfile is yet undefined. (You could pass script parameter instead.)
First off, an observation: if you want to delete the line containing the IP address and the next 6 lines you will accumulate empty lines. In your input sample there are always 7 lines in a block separated by a single blank line. If you want to preserve this structure you'd have to delete 8 lines, not seven.
Second, the probably easiest way to do this is "sed":
You may notice that the script lacks seriously in checks: checks for enough disk space, free inodes to create files, write privileges, successful operation of sed, sanity checks for the command line arguments, ... These are left as an exercise for the avid reader.
If you want to go for eight instead of seven lines in light of what i wrote above, change the "+6" to "+7" in the sed-script above.
Hello,
I have a SAS code that predominantly has comments line and the real code like below and i want to remove ONLY THE COMMENTS from the code in the single line or spanned across multiple lines.
/********************************************************************
*** This Is a Comment... (4 Replies)
Hello!
My final exam in my Linux class is tomorrow, and I was just reviewing the grep and sed commands. I came across an example, by which I got stumped: it asks to provide a sed command that deletes all lines that contain exactly 3 to 5 digit strings, from a file.
In this case, I created a... (3 Replies)
Hi,
I have been thinking of how to script this but i have no clue at all..
Could someone please help me out or give me some idea on this?
I would like to group those lines with the same first variable in each line, joining the 2nd variables with commas.
Let's say i have the following input.
... (3 Replies)
I need to run sql script from shell script which takes the input from a file and contents of file will be like :
12345
34567
78657
and query will be like :
select seq_nbr from bus_event where event_nbr='12345';
select seq_nbr from bus_event where event_nbr='34567';
select seq_nbr... (1 Reply)
Hello all!
I need to take a series of inputs passed to one shell script and pass them to a second shell script.
For example, the first shell script, script_one.sh, has the following inputs:
./script_one -u username -p password -option1 string1 -option2 -string2 ....Inside of script_one.sh... (4 Replies)
I want to write a script that deletes files inside the dir. However, the script
should also allow the user to confirm by pressing (d) key before deleting files..
#!/bin/bash
for file in $1/*
do
size='ls -l $file | cut -f 5 -d " "'
name='ls -l $file | cut -f 9 -d " "'
... (1 Reply)
Can I do something like,
if($0==/^int.*$/) {
print "Declaration"
}
for an input like: int a=5;
If the syntax is right, it is not working for me, but I am not sure about the syntax. Please help.
Thanks,
Prasanna (1 Reply)
Dears,
I need your assistance, I'm creating a shell script to read the IP address of a server and i would like to display an error message in red if the entered value is not an IP. any ideas how can i do it?:confused:
#!/bin/sh
echo "Please enter the server IP address: \c"
read IPadd... (3 Replies)
My application is coded in C++ and uses pro C to get data from oracle database. My executable file is taking more time to execute for some specified input. Is there any way to check where it spends the maximum time? (1 Reply)