AWK record in multiple lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK record in multiple lines
# 8  
Old 02-11-2010
Quote:
[...]but i know output NF = 4
Do you mean that every record has 4 fields?

---------- Post updated at 03:51 PM ---------- Previous update was at 03:45 PM ----------

Assuming all records are compete (four fields each and the fourth field is never NULL):

Code:
awk -F\; '{ r = r ? r $0 : $0 }
split(r, t) == 4 && t[4] { 
  print r; r = "" 
  }' infile

# 9  
Old 02-11-2010
Try:

Code:
awk '!NF { print "\n";; } {ORS=""; print; } ' file

# 10  
Old 02-11-2010
Quote:
Originally Posted by agritur
unfortunately not in my solution ... because Franklins use newline to identify next record
My first solution was based on the input file you provided with 2 empty lines between the records.
Not my fault.

Try this:
Code:
awk -F";" '{ORS=(NR%4)?"":"\n"}1' file

# 11  
Old 02-11-2010
Data

Quote:
Originally Posted by Franklin52
My first solution was based on the input file you provided with 2 empty lines between the records.
Not my fault.

Try this:
Code:
awk -F";" '{ORS=(NR%4)?"":"\n"}1' file


It was my fault Franklin ! touchè
input:

1111;222
222
2;333
3333;4
444
111;
22222;33
33;444

I had
1111;2222222;3333333;4
444111;22222;3333;444
Smilie

i 'd like this
1111;2222222;3333333;4444
111;22222;3333;444


ps everybody
thank for your help
# 12  
Old 02-11-2010
And what is the pattern to follow? The leading 111?
# 13  
Old 02-11-2010
Quote:
Originally Posted by agritur
It was my fault Franklin ! touchè
input:

1111;222
222
2;333
3333;4
444
111;
22222;33
33;444

I had
1111;2222222;3333333;4
444111;22222;3333;444
Smilie

i 'd like this
1111;2222222;3333333;4444
111;22222;3333;444


ps everybody
thank for your help
Yet another format of your input file?
# 14  
Old 02-11-2010
Quote:
Originally Posted by Franklin52
Yet another format of your input file?

No all , always the same format input:

my input is splitted in 1 or more lines ..... for exaple NF=4

... the output has the record completed in just a row

the awk script I think it's something like this
Code:
#!/bin/awk -f
BEGIN {
   FS=";";
   FLDmax=4;
}
{
   while (NF < FLDmax) {
      getline record;
      $0 = $0 record
   }
   print $0
}


... what do you this about this ...


ps sorry my english it's not so good.
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 select lines with maximum value of each record based on column value

Hello, I want to get the maximum value of each record separated by empty line based on the 3rd column of each row within each record? Input: A1 chr5D 634 7 82 707 A2 chr5D 637 6 82 713 A3 chr5D 637 5 82 713 A4 chr5D 626 1 82 704... (4 Replies)
Discussion started by: yifangt
4 Replies

2. Shell Programming and Scripting

Merging multiple lines to columns with awk, while inserting commas for missing lines

Hello all, I have a large csv file where there are four types of rows I need to merge into one row per person, where there is a column for each possible code / type of row, even if that code/row isn't there for that person. In the csv, a person may be listed from one to four times... (9 Replies)
Discussion started by: RalphNY
9 Replies

3. Shell Programming and Scripting

awk multiple line record retrieves only one?

I have a file with a structure like this: Database sequence: some data Database position: number Query: identifier Location: number E-value: number 0 . : . : . STRINGSTRINGSTRINGSTRING |||||||||||||||||||||||||||| ... (5 Replies)
Discussion started by: bdeads
5 Replies

4. Shell Programming and Scripting

How to compare current record,with next and previous record in awk without using array?

Hi! all can any one tell me how to compare current record of column with next and previous record in awk without using array my case is like this input.txt 0 32 1 26 2 27 3 34 4 26 5 25 6 24 9 23 0 32 1 28 2 15 3 26 4 24 (7 Replies)
Discussion started by: Dona Clara
7 Replies

5. Shell Programming and Scripting

Awk match multiple columns in multiple lines in single file

Hi, Input 7488 7389 chr1.fa chr1.fa 3546 9887 chr5.fa chr9.fa 7387 7898 chrX.fa chr3.fa 7488 7389 chr21.fa chr3.fa 7488 7389 chr1.fa chr1.fa 3546 9887 chr9.fa chr5.fa 7898 7387 chrX.fa chr3.fa Desired Output 7488 7389 chr1.fa chr1.fa 2 3546 9887 chr5.fa chr9.fa 2... (2 Replies)
Discussion started by: jacobs.smith
2 Replies

6. Shell Programming and Scripting

Splitting record into multiple records by appending values from an input field (AWK)

Hello, For the input file, I am trying to split those records which have multiple values seperated by '|' in the last input field, into multiple records and each record corresponds to the common input fields + one of the value from the last field. I was trying with an example on this forum... (4 Replies)
Discussion started by: imtiaz99
4 Replies

7. Shell Programming and Scripting

apply record separator to multiple files within a directory using awk

Hi, I have a bunch of records within a directory where each one has this form: (example file1) 1 2 50 90 80 90 43512 98 0909 79869 -9 7878 33222 8787 9090 89898 7878 8989 7878 6767 89 89 78676 9898 000 7878 5656 5454 5454 and i want for all of these files to be... (3 Replies)
Discussion started by: amarn
3 Replies

8. Shell Programming and Scripting

Multiple lines in a single column to be merged as a single line for a record

Hi, I have a requirement with, No~Dt~Notes 1~2011/08/1~"aaa bbb ccc ddd eee fff ggg hhh" Single column alone got splitted into multiple lines. I require the output as No~Dt~Notes 1~2011/08/1~"aaa<>bbb<>ccc<>ddd<>eee<>fff<>ggg<>hhh" mean to say those new lines to be... (1 Reply)
Discussion started by: Bhuvaneswari
1 Replies

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

10. Shell Programming and Scripting

Script to display record spanning over multiple lines

Following are the lines from /etc/sudoers.conf bob SPARC = (OP) ALL : SGI = (OP) ALL fred ALL = (DB) NOPASSWD: ALL ALL CDROM = NOPASSWD: /sbin/umount /CDROM,\ /sbin/mount -o nosuid\,nodev /dev/cd0a /CDROM Could you please help me with shell/perl script to display the records with... (2 Replies)
Discussion started by: Ujan
2 Replies
Login or Register to Ask a Question