FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 08-18-2012, 06:30 PM
Morning Star
 
Default About awk

Hi guys,I have some string and numeric data in like this format (one line):1 2 3 4 5 6 7 8 9 10 11 12and i want the output like this:1 2 34 5 67 8 910 11 12

How do I do that in awk?*
Thanks in advance.
Greetings,
Marco
 
Old 08-18-2012, 07:40 PM
mwillson
 
Default About awk

On Saturday, 18 August 2012 19:40:02 UTC+1, Morning Star wrote:
> Hi guys,
> I have some string and numeric data in like this format (one line):
> 1 2 3 4 5 6 7 8 9 10 11 12
> and i want the output like this:
> 1 2 3
> 4 5 6
> 7 8 9
> 10 11 12
>
>
>
> How do I do that in awk?*
>
>
> Thanks in advance.
>
>
> Greetings,
>
>
> Marco

Marco,

Does the following work for you?

BEGIN {
splitat = 3
}
{
for (i = 0; i <= NF; i++) {
printf("%s ",$i)
if ((i % splitat) == 0) printf("
")
}
}

Put into a file called split.awk and run with "awk -f split.awk your_input_file_name".

-mark


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 6968e875-eea1-4f6a-aedf-e2ec65a4153a@googlegroups.com">http://lists.debian.org/6968e875-eea1-4f6a-aedf-e2ec65a4153a@googlegroups.com
 
Old 08-20-2012, 03:17 AM
Morning Star
 
Default About awk

Thanks, Mark. You saved my time. It works for me if I change the initial i to 1 (i=1), because I don't want to get $0 to be the output. *

Greetings,

Marco



On Sun, Aug 19, 2012 at 2:40 AM, mwillson <cdr.nil@gmail.com> wrote:

On Saturday, 18 August 2012 19:40:02 UTC+1, Morning Star *wrote:

> Hi guys,

> I have some string and numeric data in like this format (one line):

> 1 2 3 4 5 6 7 8 9 10 11 12

> and i want the output like this:

> 1 2 3

> 4 5 6

> 7 8 9

> 10 11 12

>

>

>

> How do I do that in awk?*

>

>

> Thanks in advance.

>

>

> Greetings,

>

>

> Marco



Marco,



Does the following work for you?



BEGIN {

* * splitat = 3

}

{

* * for (i = 0; i <= NF; i++) {

* * * * printf("%s ",$i)

* * * * if ((i % splitat) == 0) printf("
")

* * }

}



Put into a file called split.awk and run with "awk -f split.awk your_input_file_name".



-mark





--

To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org

with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org

Archive: http://lists.debian.org/6968e875-eea1-4f6a-aedf-e2ec65a4153a@googlegroups.com
 

Thread Tools




All times are GMT. The time now is 10:23 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org