Enumerate lines until each line break using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Enumerate lines until each line break using awk
# 1  
Old 07-09-2014
Enumerate lines until each line break using awk

Hi,
I have the following data:

Code:
This	this	DT	0.99955	0	4
is	be	VBZ	1	5	7
sentence	sentence	NN	0.916667	8	16
one	one	NN	0.545078	17	20
.	.	Fp	1	20	21

This	this	DT	0.99955	22	26
is	be	VBZ	1	27	29
the	the	DT	1	30	33
second	2	JJ	0.930556	34	40
sentence	sentence	NN	0.916667	41	49
.	.	Fp	1	49	50

Hi	hello	UH	1	51	53
everyone	everyone	NN	1	54	62
!	!	Fat	1	62	63

I want to enumerate the lines in each data until the white break line, and then begin the enumeration again. Thus, the final result would look like this:

Code:
0   This	this	DT	0.99955	0	4
1   is	be	VBZ	1	5	7
2   sentence	sentence	NN	0.916667	8	16
3   one	one	NN	0.545078	17	20
4   .	.	Fp	1	20	21

0   This	this	DT	0.99955	22	26
1   is	be	VBZ	1	27	29
2   the	the	DT	1	30	33
3   second	2	JJ	0.930556	34	40
4   sentence	sentence	NN	0.916667	41	49
5   .	.	Fp	1	49	50

0   Hi	hello	UH	1	51	53
1   everyone	everyone	NN	1	54	62
2   !	!	Fat	1	62	63

Is this possible to do with
Code:
awk

?
If not, can anyone suggestion a solution in which I can arrive at the final result?

In advance, thank you!
# 2  
Old 07-09-2014
Code:
awk 'NF{$0=c++ FS $0}!NF{c=0}1' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to remove lines that do not start with digit and combine line or lines

I have been searching and trying to come up with an awk that will perform the following on a converted text file (original is a pdf). 1. Since the first two lines are (begin with) text they are removed 2. if $1 is a number then all text is merged (combined) into one line until the next... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. UNIX for Beginners Questions & Answers

awk script for pattern match and line break

Hi, I have input which reads like 9089.00 ----- kl jkjjljk lkkk; (909099) 9097.00 ----- HGJJHHJ jcxkjlkjvhvlk jhdkjksdfkhfskd 898.00 ----- HHHH I am trying to do something like this - As soon as I found pattern match "XYZ.00-----" it will insert a line break to the input and will go to... (3 Replies)
Discussion started by: Indra2011
3 Replies

3. Shell Programming and Scripting

Break line content into multiple lines using delimiter

I need to break the line after every 3rd semi colon(;) using Unix shell scripting Input.txt ABC;DEF;JHY;LKU;QWE;BVF;RGHY; Output.txt ABC;DEF;JHY; LKU;QWE;BVF; RGHY; (1 Reply)
Discussion started by: meet_calramz
1 Replies

4. Shell Programming and Scripting

Break lines that appear together

Hello to all May you help me with a sed or awk script to fix the text below please. I have a file where all lines should have 67 characters but from time to time 2 lines appear together like below. * First column always has 15 characters * Second column always has 32 characters * 3rd,... (5 Replies)
Discussion started by: Ophiuchus
5 Replies

5. Shell Programming and Scripting

How to calculate mean in AWK? line by line several files, thousands of lines

I'm kinda stuck on this one, I have 7 files with 30.000 lines/file like this 050 0.023 0.504336 050 0.024 0.529521 050 0.025 0.538908 050 0.026 0.537035 I want to find the mean line by line of the third column from the files named like this: Stat-f-1.dat .... Stat-f-7.dat Stat-s-1.dat... (8 Replies)
Discussion started by: AriasFco
8 Replies

6. Shell Programming and Scripting

BASH: Break line, read, break again, read again...

...when the lines use both a colon and commas to separate the parts you want read as information. The first version of this script used cut and other non-Bash-builtins, frequently, which made it nice and zippy with little more than average processor load in GNOME Terminal but, predictably, slow... (2 Replies)
Discussion started by: SilversleevesX
2 Replies

7. Shell Programming and Scripting

Awk to Break lines to multiple lines.

Input File: nawk -F "|" '{ for(i=1;i<=NF;i++) { if (i == 2) {gsub(",","#",$i);z=split($i,a,"")} else if (i == 3) {gsub(",","#",$i);z=split($i,b,"")} } if(z > 0) for(i=1;i<=z;i++) print $1,a,"Test"; if(w > 0) for(j=1;j<=w;j++) ... (1 Reply)
Discussion started by: pinnacle
1 Replies

8. Shell Programming and Scripting

Break lines up into single lines after each space in every line

It sounds a bit confusing but what I have is a text file like the example below (without the Line1, Line2, Line3 etc. of course) and I want to move every group of characters into a new line after each space. Example of text file; line1 .digg-widget-theme2 ul { background: rgb(0, 0, 0) none... (7 Replies)
Discussion started by: lewk
7 Replies

9. Shell Programming and Scripting

join lines on line break in files

i had a file where lines appear to be broken when they shouldn't eg Line 1. kerl abc sdskd sdsjkdlsd sdsdksd \ Line 2. ksdkks sdnjs djsdjsd i can do a shift join to combine the lines but i there are plenty of files with this issue Line 1. kerl abc sdskd sdsjkdlsd sdsdksd ksdkks sdnjs... (6 Replies)
Discussion started by: mad_man12
6 Replies

10. Shell Programming and Scripting

Break one line to many lines using awk

Break one line to many lines using awk The below code works but i want to implement without combining field 2 and 3 and then splitting i would like to do this in one command instead of writing multiple commands and creating multiple lines. nawk -F"|" '{print $1,$2SUBSEP$3}' OFS="|" file >... (16 Replies)
Discussion started by: pinnacle
16 Replies
Login or Register to Ask a Question