replace blank line number


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting replace blank line number
# 1  
Old 12-01-2011
replace blank line number

hlow all i need help
how can i replace blank number with awk
input.txt
Code:
300::|355264313178490
301::|358814003239510

302::|358316038113400
303::|357954002633660
304::|354072040694090
305::|356956015214190
306::|352943020525180
307::|359574033836610
308::|381810990023580

so will be like this output
Code:
300::|355264313178490
301::|358814003239510
302::|NULL
303::|358316038113400
304:|357954002633660
305::|354072040694090
306::|356956015214190
307::|352943020525180
308::|359574033836610
309::|381810990023580

blank number will replace with any string ex:NULL or BLANK etc so wc -l in list 9 lines

thx for your advice
# 2  
Old 12-01-2011
Code:
nawk  -F"[:\|]" 'BEGIN{a=301;}{if($4==""){$4="NULL"} printf("%s::|%s\n",a,$4); a=a+1}' inputfile

# 3  
Old 12-01-2011
Code:
perl -ne 's/^\n/302::\|NULL\n/; print $_' inputfile

Sorry, the above code snippet would not work as per requirement. My mistake.. Didn't read it thoroughly.

Last edited by balajesuri; 12-01-2011 at 05:12 AM..
This User Gave Thanks to balajesuri For This Post:
# 4  
Old 12-01-2011
Quote:
Originally Posted by itkamaraj
Code:
nawk  -F"[:\|]" 'BEGIN{a=301;}{if($4==""){$4="NULL"} printf("%s::|%s\n",a,$4); a=a+1}' inputfile

@itkamaraj thx for your solveSmilie
# 5  
Old 12-01-2011
I was trying a generic solution..
Code:
 awk -F: '{if($1!=""){print $1+u":"$2":"$3;}else {print t+1"::|Null";++u}t=$1+u}' inputfile

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. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

3. Shell Programming and Scripting

Replace comma and blank with comma and number

I, I have a file and i need to replace comma and blank space with comma and 0. cat file.txt a,5 b,1 c, d, e,4 I need the output as cat file.txt a,5 b,1 c,0 d,0 (4 Replies)
Discussion started by: jaituteja
4 Replies

4. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

5. Shell Programming and Scripting

Replace first number of each line in a file with another number

Hi, I have a set of files in a directory that I have to read and replace the first occurrence of a number with another dummy number. This is what I have so far but it does not seem to work. The files have lot of other data in each row and each data element is separated by ,@, for file in... (13 Replies)
Discussion started by: scorpioraghu
13 Replies

6. Shell Programming and Scripting

replace line starting with not a number

Dear users, I have a file like this: geometry,geometry_vertex_count,Id,strnum,platecode,datatype,dtnum,refnum,appearance,disappeara,color,geogdesc,datatype_ft_style,import_notes "<LineString><coordinates>-130.6539,51.5103,0 -130.7708,51.6287,0 -130.8356,51.6832,0 -130.9211,51.7772,0... (5 Replies)
Discussion started by: Gery
5 Replies

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

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

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

10. 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
Login or Register to Ask a Question