Transpose with two newlines as delimiter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Transpose with two newlines as delimiter
# 8  
Old 01-27-2010
Anybody?
# 9  
Old 01-28-2010
if you want the o/p as you mention earlier the code will be the same but the input file have to be as below:-

Code:
a 1 2 3
b 4 5 6 
c
 
a 6 7 8 
b
c

a 4 7 9 
b 6 8 5 
c 0 8 7

and change the space to tab in code as below:-

Code:
awk '
NF{ a[$1]=a[$1]"\t"$2 ; next }
END{for (i in a) {print i,a[i] } }
'    infile.txt | awk '
   BEGIN{ FS="\t" }

   {
      for (f = 1; f <= NF; f++)
         a[NR, f] = $f
   }
   NF > nf { nf = NF }
   END {
      for (f = 1; f <= nf; f++)
         for (r = 1; r <= NR; r++)
            
                printf"%s%s",a[r, f],(r==NR ? "\n" : FS)

   } 
'


Last edited by ahmad.diab; 01-28-2010 at 04:30 AM..
# 10  
Old 01-28-2010
Thanks for the reply.

I don't have the a,b,c placeholders for empty rows. Where there are no values for a,b,c, I don't have anything. (not even a blank line). I have multiple rows (a,b,c is just an example) so I don't want to stuff the input file with the missing a,b,c values.

Can I use the empty lines as a delimiter and fill the values of a,b and c accordingly?
# 11  
Old 01-29-2010
Can I build the columns as and when they appear in the file? For example if the first group has a and b only, I will get a and b, then if the second group has a,b and c, then the c column will be appended to my output and so on.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Remove newlines

Hi buddy's my file are like this: s.no,name,band,sal 1,"suneel",,10 2,"bargav sand",,20 30," ebdug gil",,4 but i want s.no,name,band,sal 1,"suneel",,10 2,"bargav sand",,20 30,"ebdug gil",,4 any command or Shell script for this. please help me it's urgent to implement (33 Replies)
Discussion started by: Suneelbabu.etl
33 Replies

2. Shell Programming and Scripting

Perl Code to change file delimiter (passed as argument) to bar delimiter

Hi, Extremely new to Perl scripting, but need a quick fix without using TEXT::CSV I need to read in a file, pass any delimiter as an argument, and convert it to bar delimited on the output. In addition, enclose fields within double quotes in case of any embedded delimiters. Any help would... (2 Replies)
Discussion started by: JPB1977
2 Replies

3. Shell Programming and Scripting

Shell script to put delimiter for a no delimiter variable length text file

Hi, I have a No Delimiter variable length text file with following schema - Column Name Data length Firstname 5 Lastname 5 age 3 phoneno1 10 phoneno2 10 phoneno3 10 sample data - ... (16 Replies)
Discussion started by: Gaurav Martha
16 Replies

4. Shell Programming and Scripting

Replace commas with newlines

Good afternoon, I am trying to read user input. Here is what I have so far: echo "Type the Container ID for every container that you want subnets exported" echo "for (with comma between each one, for example... 1,45,98)" echo -n "if you want every one listed, then just type ALL in caps... (2 Replies)
Discussion started by: brianjb
2 Replies

5. Shell Programming and Scripting

How to cut by delimiter, and delimiter can be anything except numbers?

Hi all, I have a number of strings like below: //mnt/autocor/43°13'(33")W/ and i'm trying to get the numbers in this string, for example 431333 please help thanks ahead (14 Replies)
Discussion started by: sunnydanniel
14 Replies

6. Shell Programming and Scripting

Need help with eliminating newlines with Perl

Good morning, I need some help with getting rid of newlines with the output from a MYSQL query and putting the information into the right format that I need. Here is the script as it is today: #!/usr/bin/perl my $uda = system("/opt/incontrol/mysql/bin/mysql -u root -ppassword... (2 Replies)
Discussion started by: brianjb
2 Replies

7. Shell Programming and Scripting

Delete newlines after every one space

Hi All, I have a file which looks like this: abc 3456 computer 3214 printer 0.9823 computer 3214 Can anyone please let me know how I can format my text like this? abc 3456 computer 3214 printer 0.9823 computer 3214 I know how to space to newlines using tr but don't know how to do... (4 Replies)
Discussion started by: shoaibjameel123
4 Replies

8. Shell Programming and Scripting

Extract pattern before two newlines

Hi All, My file looks like this: 1 2 3 3 4 5 6 7 8 8 7 6 3 4 5 3 6 7 3 4 5 1 2 4 3 4 6 2 4 6 As you can see there are two newlines after the next pattern of numbers begin. (4 Replies)
Discussion started by: shoaibjameel123
4 Replies

9. Shell Programming and Scripting

Substring based on delimiter, finding last delimiter

Hi, I have a string like ABC.123.XYZ-A1-B2-P1-C4. I want to delimit the string based on "-" and then get result as only two strings. One with string till last hyphen and other with value after last hyphen... For this case, it would be something like first string as "ABC.123.XYZ-A1-B2-P1" and... (6 Replies)
Discussion started by: gupt_ash
6 Replies

10. OS X (Apple)

Add CRs (newlines)

I have a long file originally created with vi but at some point saved with MS Word. At another time I substituted all occurrences of ^M with XXX. Now I'd like to get this back to vi but with the XXX converted to newline. I'm using whatever version of vim Apple employs. Thanks, Gale (10 Replies)
Discussion started by: Gale Gorman
10 Replies
Login or Register to Ask a Question