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
# 8  
Old 01-28-2012
Code:
# awk --version
awk: Not a recognized flag: -
Usage: awk [-u] [-F Character][-v Variable=Value][-f File|Commands][Variable=Value|File ...]


Last edited by Franklin52; 01-30-2012 at 07:50 AM.. Reason: Please use code tags for code and data samples, thank you
# 9  
Old 01-30-2012
I am not able to interpret this:
Code:
awk '/^[^ ]/{en=$1}/^ *inet /{print en,$2}'

Can you please help?

Last edited by Franklin52; 01-30-2012 at 07:51 AM.. Reason: Please use code tags for code and data samples, thank you
# 10  
Old 01-31-2012
/^[^ ]/ -- matches all lines that do not start with space (the first ^ is the anchor beginning of the line, the second one in [^ ] means negation, that is [^ ] is any character but space.
en=$1 --store the first field in a var
/^ *inet/ -- matches the lines starting with zero or more spaces followed by "inet"
print en,$2 -- print the stored stuff and second field
# 11  
Old 01-31-2012
Wow... Mirni that was really helpful and it modified it a little bit and it worked for me:

Code:
One last question: I have the output given below:
File system devifs is not mounted.
File system devifs1 is not mounted.

File system devipfsnew is mounted on 4 nodes:
  10.23.12.16   tblsdev01
  10.23.12.31   tblsdev02
  10.23.12.95   st58tblsdev
  10.23.12.111  tblsdev03

File system devesnew is mounted on 4 nodes:
  10.23.15.16   tblsdev01
  10.23.15.95   sj55tblsdev04
  10.23.15.31   tblsdev02
File system gpfsdmin is not mounted.
File system gpfsapp is not mounted.


How can I get the following output:

devipfsnew:tblsdev01
devipfsnew:tblsdev02
devipfsnew:st58tblsdev
devipfsnew:tblsdev03
devesnew:tblsdev01
devesnew:sj55tblsdev04
devesnew:tblsdev02

I tried to apply the same login you explained but I am not able to get it.....

Please help me.....

# 12  
Old 01-31-2012
Using the same logic:
Code:
awk '/is mounted/{fs=$3}/^ *10/{print fs":"$2}' mountedFS.txt

If the line contains "is mounted", store the third field.
If the line starts with zero or more spaces followed by '10', print stored var, colon, second field.
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