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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting In a file, replace blank line by the last line not blank above
# 8  
Old 02-26-2017
General solution:
Code:
awk '{for(i=1; i<=NF; i++) if($i=="") $i=p[i]; else p[i]=$i}1' FS=\; OFS=\;  file


--
Note: one needs to test if the field is empty, otherwise it will fail if the one of the fields is the number "0"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Deleting the last non blank line from a file

PGW|PGW_CDR_|2017-06-23 141946|2017-07-17 131633|2017-08-21 PGW|PGW_CDR_|2017-06-23 141946|2017-07-17 131633|2017-08-21 PGW|PGW_CDR_|2017-06-23 141946|2017-07-17 131633|2017-08-21 PGW|PGW_CDR_|2017-06-23 141946|2017-07-17 131633|2017-08-21 PGW|PGW_CDR_|2017-06-23 141946|2017-07-17... (6 Replies)
Discussion started by: swathi reddy1
6 Replies

2. Shell Programming and Scripting

Need help to replace a pattern with a blank line

Need help to replace the line beginning with tcp_sendspace with a blank line. # 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... (11 Replies)
Discussion started by: sags007_99
11 Replies

3. 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

4. Shell Programming and Scripting

Fill the empty line by adding line before blank line

FIle A "A" 2 aa 34 3 ac 5 cd "B" 3 hu 67 4 fg 5 gy output shud be A"" 2 aa 34 "A" 3 ac 34 "A" 5 cd 34 "B" 3 hu 67 "B" 4 fg 67 "B" 5 gy 67 (6 Replies)
Discussion started by: cdfd123
6 Replies

5. 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

6. 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

7. Shell Programming and Scripting

how to get the blank line number of a file?

I want to get the blank line number of a file. example: 9000|9000|WW|1|1|SL|472|472|LC|2272|1072|MTY|niceDay 9000|9000|WW|1|1|SL|470|470|MC|1270|1172|MPVT|nice 9000|9000|WW|1|1|SL|472|472|LC|1072|1672|MBD|Sonice 9000|9000|WW|1|1|SL|473|473|LF|1173|1173|MTY|nice666 I want to get... (5 Replies)
Discussion started by: robbiezr
5 Replies

8. Shell Programming and Scripting

Remove last blank line of file

I have a number of files (arranged in directories) which have last line blank, I am trying to synchronize my code with other env and due to this blank lines, all files error out as different although only difference is that of balnk line at end of file. Is there a way I can recursively... (2 Replies)
Discussion started by: ruchimca
2 Replies

9. Shell Programming and Scripting

ignoring blank line in a file

i have a file called Cleaner1.log . This files have some blank lines also.My requirement is that it should ignore the blank lines and give me the lines that contain some data. I m using this logic in a script: below the contents of file : Maximum Time Taken for Processing(Failed) RR... (4 Replies)
Discussion started by: ali560045
4 Replies

10. Shell Programming and Scripting

how to delete a first blank line from the file

I have a file which has the first blank line: sundev22$cat /t1/bin/startallocs /t1/bin/startallocsys 123 sundev22$ Is there a command to remove this first blank line? Thanks for help -A (4 Replies)
Discussion started by: aoussenko
4 Replies
Login or Register to Ask a Question
FBB::lm(3bobcat)					      OFoldStream manipulator						  FBB::lm(3bobcat)

NAME
FBB::lm - Manipulator setting left margins of OFoldStream objects SYNOPSIS
#include <bobcat/ofoldstream> or #include <bobcat/ofoldstreambuf> Linking option: -lbobcat DESCRIPTION
The lm class implements a manipulator that can be inserted into OFoldStream objects to set the stream's left margin to a requested value. Depending on the tab-setting of the OFoldStream the inserted value represents the number of blank space characters or the number of tab-characters that will be used for the left margin. The request will be processed at the next newline character or std::flush or std::endl manipulator that is inserted into the stream. If a line is still once an lm object and a flush manipulator are inserted into the stream then the new left margin will be effective at the next word inserted into that line (cf., the example section below). A bad_cast exception is thrown when the manipulator is inserted into an ostream that is not using a OFoldStreambuf buffer. NAMESPACE
FBB All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB. INHERITS FROM
- CONSTRUCTOR
o lm(size_t newValue): The standard copy constructor is available. MEMBER FUNCTIONS
There are no public or protected member functions in this class. EXAMPLE
#include <iostream> #include <bobcat/ofoldstream> using namespace std; using namespace FBB; int main() { OFoldStream out(cout, 0, 80); out << "hello world (left margin is 0)" << lm(4) << " " "this uses a 4 character wide left margin " << lm(0) << flush << "at column 0 again "; return 0; } FILES
bobcat/lm - defines the class interface SEE ALSO
bobcat(7), manipulators(3bobcat), mlm(3bobcat), ofoldstream(3bobcat) BUGS
None Reported. DISTRIBUTION FILES
o bobcat_3.01.00-x.dsc: detached signature; o bobcat_3.01.00-x.tar.gz: source archive; o bobcat_3.01.00-x_i386.changes: change log; o libbobcat1_3.01.00-x_*.deb: debian package holding the libraries; o libbobcat1-dev_3.01.00-x_*.deb: debian package holding the libraries, headers and manual pages; o http://sourceforge.net/projects/bobcat: public archive location; BOBCAT
Bobcat is an acronym of `Brokken's Own Base Classes And Templates'. COPYRIGHT
This is free software, distributed under the terms of the GNU General Public License (GPL). AUTHOR
Frank B. Brokken (f.b.brokken@rug.nl). libbobcat1-dev_3.01.00-x.tar.gz 2005-2012 FBB::lm(3bobcat)