![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| PHP arrays in arrays | JerryHone | Web Programming, Web 2.0 and Mashups | 3 | 03-13-2009 02:19 PM |
| awk arrays can do this better - but how? | littleIdiot | Shell Programming and Scripting | 1 | 02-03-2009 05:13 AM |
| Need Help with awk and arrays | fusionX | Shell Programming and Scripting | 7 | 02-11-2008 06:41 PM |
| arrays in awk??? | craigsky | Shell Programming and Scripting | 3 | 08-27-2007 09:13 PM |
| KSH and arrays | whited05 | Shell Programming and Scripting | 1 | 06-24-2005 12:07 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
arrays in awk
Hi,
I have the following data in a file for example: Name="Fred","Bob","Peterson","Susan","Weseley" Age="24","30","28","23","45" Study="English","Engineering","Physics","Maths","Psychology" Code="0","0","1","1","0" Name="Fred2","Bob2","Peterson2","Susan2","Weseley2" Age="23","29","25","21","44" Study="English2","Engineering2","Physics2","Maths2","Psychology2" Code="1","1","1","1","1" Can you help me with an awk script to print the file such as: Name,Age,Study,Code Fred,24,English,0 Bob,30,Engineering,0 Peterson,28,Physics,1 Susan,23,Maths,1 Weseley,45,Psychology,0 Fred2,23,English2,1 Bob2,29,Engineering2,1 . . . Thanks Last edited by james2009; 04-17-2009 at 08:34 AM.. |
|
||||
|
@panyam, wrong output
@OP, here's a Perl solution Code:
my $file="file";
my @array;
open(IF,"<",$file) or die "Cannot open input file:$!\n";
while(my $line = <IF>){
chomp($line);
push(@array,[split/=|,/,$line]);
}
for $i ( 0 .. $#{$array[0]} ) {
for $j ( 0 .. $#array ) {
if( $j==$#array){
print "$array[$j][$i]\n";
}else{
print "$array[$j][$i] ";
}
}
}
Code:
# ./test.pl Name Age Study Code "Fred" "24" "English" "0" "Bob" "30" "Engineering" "0" "Peterson" "28" "Physics" "1" "Susan" "23" "Maths" "1" "Weseley" "45" "Psychology" "0" |
|
||||
|
James the solution was already present in the forum . I just googled it.
Row to column transpose I hope the given shell script ( in the URL) work fine.Before running the script make sure that input file is a comma seperated file. this is wht the op i got avalon:/disk1/jvsh/TEST>awk -f testawk.awk 1.txt Name Age Study Code Fred 24 English 0 Bob 30 Engineering 0 Peterson 28 Physics 1 Susan 23 Maths 1 Weseley 45 Psychology 0 Last edited by panyam; 04-17-2009 at 05:42 AM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|