Need help to replace a pattern with a blank line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help to replace a pattern with a blank line
# 1  
Old 01-25-2012
Need help to replace a pattern with a blank line

Need help to replace the line beginning with tcp_sendspace with a blank line.
Code:
# cat if
en0: flags=1e080863,480<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64BIT,CHECKSUM_OFFLOAD(ACTIVE),CHAIN>
        inet 10.27.53.21 netmask 0xffffff00 broadcast 10.207.52.255
        inet 10.27.58.48 netmask 0xffffff00 broadcast 10.207.52.255
         tcp_sendspace 262144 tcp_recvspace 262144 rfc1323 1
en1: flags=1e080863,480<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64BIT,CHECKSUM_OFFLOAD(ACTIVE),CHAIN>
        inet 10.26.52.25 netmask 0xffffff00 broadcast 10.207.52.255
        inet 10.26.52.41 netmask 0xffffff00 broadcast 10.207.52.255
         tcp_sendspace 262144 tcp_recvspace 262144 rfc1323 1
lo0: flags=e08084b,c0<UP,BROADCAST,LOOPBACK,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64BIT,LARGESEND,CHAIN>
        inet 127.0.0.1 netmask 0xff000000 broadcast 127.255.255.255
        inet6 ::1%1/0
         tcp_sendspace 131072 tcp_recvspace 131072 rfc1323 1

Also, I am not able to figure out how can I get the following output:
Code:
en0:10.27.53.21 
en0:10.27.53.21
       
en1:10.26.52.25
en1:10.26.52.41

Thanks in advance....

Last edited by Franklin52; 01-26-2012 at 03:46 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 01-25-2012
If you just want those lines to be blank:

Code:
sed 's/^tcp_sendspace.*//' input-file >output-file

If you'd like not to have the 'holes' in the file then
Code:
sed '/^tcp_sendspace/d' input-file >output-file

Your example output showed the elimination of all but the en.* lines. If that's what you want use grep for ^en.* or if you really want the blank lines:

Code:
awk '/^en[0-9]/ {print; next} {printf( "\n" );}' input-file >output-file

awk '
# 3  
Old 01-26-2012
Thanks for the reply but none of these server my purpose:

1)
Code:
sed 's/^tcp_sendspace.*//'

and
Code:
sed '/^tcp_sendspace/d'

DO NOT replace the line starting with ^tcp_space with a blank line. I am on AIX.

2)
Code:
# awk '/^en[0-9]/ {print; next} {printf( "\n" );}' filename
en0: flags=1e080863,480<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64BIT,CHECKSUM_OFFLOAD(ACTIVE),CHAIN>



en1: flags=1e080863,480<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64BIT,CHECKSUM_OFFLOAD(ACTIVE),CHAIN>

I get the output seen above.....


I need something like:
Code:
en0:10.27.53.21 
en0:10.27.53.21
       
en1:10.26.52.25
en1:10.26.52.41


Last edited by Franklin52; 01-26-2012 at 03:47 AM.. Reason: Please use code tags for code and data samples, thank you
# 4  
Old 01-26-2012
Would this be good enough?
Code:
 
$ awk '/^[^ ]/{en=$1}/^ *inet /{print en,$2}' infile
en0: 10.27.53.21
en0: 10.27.58.48
en1: 10.26.52.25
en1: 10.26.52.41
lo0: 127.0.0.1

This User Gave Thanks to mirni For This Post:
# 5  
Old 01-27-2012
That one does not give me the required output either....

Which OS are you using?
# 6  
Old 01-27-2012
Perl.
Code:
perl -ane 'if (/flags=/ .. /tcp_sendspace/) {
    (/flags=/) && ($x = $F[0]);
    (/inet/) && print "$x $F[1]\n";
    (/tcp_sendspace/ && !eof) && print "\n";
}' inputfile

# 7  
Old 01-27-2012
Quote:
That one does not give me the required output either....
What output does it give you, if any? The more specific you are in your questions, requirements and responses, the more accurate and faster you receive help.
Can you please post what version of awk are you using:
Code:
awk --version

Is what you posted in your first post exactly what you are trying to process?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

In a file, replace blank line by the last line not blank above

Dear All, In a CSV file, say that a given column has been extracted. In that column, information is missing (i.e. blank lines appear). I would like to replace the blank lines by the last valid line (not blank) previously read. For example, consider the extract below: 123 234 543 111... (7 Replies)
Discussion started by: bagvian
7 Replies

2. UNIX for Dummies Questions & Answers

How to delete blank line/s before and after a search pattern?

Hi, Test file x.txt below. This file is generated by a program that I unfortunately do not have control on how it gets presented/generated. create PACKAGE "XXX_INTERFACE_DEFECT_RPT_TEST" is TYPE refCursor IS REF CURSOR; Function queryRecords ( p_status varchar2, ... ... ... )... (4 Replies)
Discussion started by: newbie_01
4 Replies

3. Shell Programming and Scripting

I need to know how to replace a line after a pattern match with an empty line using SED

Hi How Are you? I am doing fine! I need to go now? I will see you tomorrow! Basically I need to replace the entire line containing "doing" with a blank line: I need to the following output: Hi How Are you? I need to go now? I will see you tomorrow! Thanks in advance.... (1 Reply)
Discussion started by: sags007_99
1 Replies

4. Shell Programming and Scripting

replace blank line number

hlow all i need help how can i replace blank number with awk input.txt 300::|355264313178490 301::|358814003239510 302::|358316038113400 303::|357954002633660 304::|354072040694090 305::|356956015214190 306::|352943020525180 307::|359574033836610 308::|381810990023580 so will be like... (4 Replies)
Discussion started by: zvtral
4 Replies

5. Shell Programming and Scripting

pattern match and replace another pattern in same line

I have a pattern username:x:32005:32006::/usr/local/user:/bin/bash I need to match the line containing username and replace /bin/bash with /usr/local/my/bin/noshell So it becomes username:x:32005:32006::/usr/local/user:/usr/local/my/bin/noshell (7 Replies)
Discussion started by: anilcliff
7 Replies

6. Shell Programming and Scripting

Awk script to match pattern till blank line

Hi, I need to match lines after a pattern, upto the first blank line. Searched in web and some forums but coulnt find the answer. where <restart_step> = 10 -- Execute query 20 -- Write the contents to the Oracle table 30 -- Writing Contents to OUTPUT... (7 Replies)
Discussion started by: justchill
7 Replies

7. Shell Programming and Scripting

Replace two blank line with a single blank line

Hi Guys, I have a file in which each set of records are separated by two blank line. I want to replace it with a single blank line. Can you guys help me out? Regards, Magesh (9 Replies)
Discussion started by: mac4rfree
9 Replies

8. Shell Programming and Scripting

how to replace a line in file with blank line

Hi I nned cmd to which will help me to replace a line in file with blank line e.g. file1 a b c d e after running cmd I shud get file1 b c d e (5 Replies)
Discussion started by: tarunn.dubeyy
5 Replies

9. Shell Programming and Scripting

Need help in sed command (adding a blank line btw each block generated by pattern)

Hello friends, I have a C source code containing sql statements. I use the following sed command to print all the sql blocks in the source code.... sed -n "/exec sql/,/;/p" Sample.cpp The above sed command will print the sql blocks based on the pattern "exec sql" & ";"... (2 Replies)
Discussion started by: frozensmilz
2 Replies

10. Shell Programming and Scripting

sed - Replace Line which contains the Pattern match with a new line

I need to replace the line containing "STAGE_DB" with the line "STAGE_DB $DB # database that contains the table being loaded ($workingDB)" Here $DB is passed during the runtime. How can I do this? Thanks, Kousikan (2 Replies)
Discussion started by: kousikan
2 Replies
Login or Register to Ask a Question