AWK record in multiple lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK record in multiple lines
# 1  
Old 02-11-2010
AWK record in multiple lines

Hi everyboby

this is my problem

I Have this input
Code:
1111;222
222
2;333
3333;4444


111;
22222;33
33;
444


and I need this output

Code:
1111;2222222;3333333;4444
111;22222;3333;444


thank 's a lot
N.B. every output record has 4 fields

Last edited by Franklin52; 02-11-2010 at 09:37 AM.. Reason: Please use code tags!
# 2  
Old 02-11-2010
Try this:
Code:
awk '$1=$1{gsub(" ","")}1' RS= file

Use nawk or /usr/xpg4/bin/awk on Solaris if you get errors.
# 3  
Old 02-11-2010
Something like this ?

Code:
  
sed '/^$/d' inputfile | awk 'NR%4 > 0 {a=a $0;next} {b=a $0; a=""; print b}'

Assumed that the record is splitted into 4 lines.

Great Franklin, Your solution works fine.

Last edited by panyam; 02-11-2010 at 09:58 AM..
# 4  
Old 02-11-2010
Quote:
Originally Posted by panyam
Something like this ?

Code:
  
sed '/^$/d' inputfile | awk 'NR%4 > 0 {a=a $0;next} {b=a $0; a=""; print b}'

Assumed that the record is splitted into 4 lines.

Great Franklin, Your solution works fine.


thank's ..... but I don t known if the record is splitted into 4 lines ..
It could be splitted like this
X;1111;222
222
2;333
3333;4444


X;111;22222;3333;444
4444

and I need
X;1111;2222222;3333333;4444
X;111;22222;3333;4444444

I only know that if the record is Good it has NF defined and next record will start with X


thanks you very much
# 5  
Old 02-11-2010
Franklins solution works great in all the situations.
# 6  
Old 02-11-2010
Quote:
Originally Posted by panyam
Franklins solution works great in all the situations.
unfortunately not in my solution ... because Franklins use newline to identify next record

Code:
1111;222
222
2;333
3333;4444
111;
22222;33
33;
444


it's converted in
Code:
1111;2222222;3333333;4444111;22222;3333;444

but i know output NF = 4
so I need

Code:
1111;2222222;3333333;4444
111;22222;3333;444



thanks panyam and thanks franklin

Last edited by radoulov; 02-11-2010 at 10:42 AM.. Reason: Please use code tags!
# 7  
Old 02-11-2010
agritur,

Based on your previous post , i assumed that , if the record is Good it shoud start with "X", based on that:

Code:
 
awk '$1=$1{gsub(" ","");$0="X"$0}1' RS="X"  input_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 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