Script for Removing Lines from File / Blocking internet connection


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script for Removing Lines from File / Blocking internet connection
# 1  
Old 04-16-2011
Script for Removing Lines from File / Blocking internet connection

Hey all. I am trying to write some scripts and need some assistance.

One:
I already have a script that appends lines to a file. I need a script that will remove those lines from that file, and have no idea how to go about doing this. Just need the command (if any) that can remove lines.

Two:
I am writing a script that will disable all outgoing HTTP connections and also have no idea how to do this. Any assistance would be great.

Thank you!
# 2  
Old 04-17-2011
Well, if you know which line needs to be removed, you can get the line number and use sed
eg: Lets say you want to remove the line with the string "Remove me from the file"

Code:
#!/bin/ksh
linenum=`grep -n "Remove me from the file" filename | cut -f1 -d":"`
sed -i "${linenum}d" filename

or you can use grep

Code:
#!/bin/ksh
grep -v "Remove me from the file" filename >> filename.$$
mv filename.$$ filename

For blocking the http connections, probably you can use iptables,ipfilters etc

regards,
Ahamed
# 3  
Old 04-17-2011
for one:

Do you know the line number for which the content needs to be removed or is that the content that needs to be removed?

Both of them can be done by inverse selection logic.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing lines from a file

I have a file `/tmp/wrk` containing filenames with paths. I want to remove filenames from this file, for example remove all filenames containing alja cagr cavt clta cmdo or corl remove all filenames containing data for days in region `d.2016.001` to `d.2016.207` remove all filenames... (10 Replies)
Discussion started by: kristinu
10 Replies

2. Shell Programming and Scripting

Removing 3 consecutive lines from script

Hi I need to remove three consecutive lines of code which appear multiple times during a script. Two of the lines also appear in other parts of the scripts and need to stay so I can't strip out the code per se - It needs to be the exact three lines. Hope that makes sense ! Any help much... (5 Replies)
Discussion started by: Grueben
5 Replies

3. Shell Programming and Scripting

Removing specific lines from script files.

Hello, Activity to perform: 1. Find all of the "*.tmp" files in a given user directory 2. Determine which ones have "find" in them. 3. Replace the "find sequence" of commands with a "list set" of commands. Example: Original file: -------------- define lastn1 = "A" define... (7 Replies)
Discussion started by: manishdivs
7 Replies

4. Shell Programming and Scripting

Removing lines from a file being used by another process using SHELL script

Hi All, Need a small help in writing a shell script which can delete a few lines from a file which is currently being used by another process. File gets appended using tee -a command due to which its size is getting increased. Contents like : 25/09/2012 05:18 Run ID:56579677-1 My... (3 Replies)
Discussion started by: nikhil8
3 Replies

5. Shell Programming and Scripting

blocking connection message in sftp

when i use below sftp command we get connectuiobn message , is there a way to block it. cnt=`sftp -b 'count.sh' <username>@<password>:/gsmtmeg1/java5/docs/common/ | grep -v '^sftp>' | wc -l`;echo $cnt Output ** RESTRICTED ACCESS ** You are authorized to use this system for approved... (0 Replies)
Discussion started by: lalitpct
0 Replies

6. UNIX for Dummies Questions & Answers

removing several lines from a file

Hi folks, I have a long string of DNA sequences, and I need to remove several lines, as well as the line directly following them. For example, here is a sample of my starting material: >548::GY31UMJ02DLYEH rank=0007170 x=1363.5 y=471.0 length=478... (1 Reply)
Discussion started by: kkohl78
1 Replies

7. Solaris

Blocking outgoing connection to ports/host in solaris

Hi, I want to block all outgoing connection ( the IMAP ) to my exchnage . I have to do it in my solaris server; from solaris host no outgoing connection can be made to the imap server. Please help me to configure that. I am new in solaris. Kind regards, Akhtar (2 Replies)
Discussion started by: akhtarbd
2 Replies

8. Solaris

Internet connection

I got solaris 10 works, but I cannot set up my internet connection. When I ping a website and i open the web browser, it doesn't work. When the installation asked 'Am I in a network?' i answerd 'no'. I think this is my minstake. How can i get Internet, now? I have a ADSL modem (not router).... (5 Replies)
Discussion started by: mghis
5 Replies

9. Linux

SELinux is blocking Internet on my machine with FC9

Hi, I am facing an issue with SEliux blocking my internet usage Was searching online for its fix. I thnk their has bug raised and fixed FC10. but anybody guide to get it fixed on FC9. thanks in advance Prakash (1 Reply)
Discussion started by: prakash.kudreka
1 Replies

10. Shell Programming and Scripting

Removing lines within a file

Hi There, I've written a script that processes a data file on our system. Basically the script reads a post code from a list file, looks in the data file for the first occurrence (using grep) and reads the line number. It then tails the data file, with the line number just read, and outputs to a... (3 Replies)
Discussion started by: tookers
3 Replies
Login or Register to Ask a Question