Computing.Net > Forums > Programming > Split one column into three with awk

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Split one column into three with awk

Reply to Message Icon

Name: mohairsam
Date: September 21, 2009 at 02:15:41 Pacific
OS: Linux i686
Product: Macmillan Linux for windows
Subcategory: Batch
Comment:

I want to convert

1
2
3
4
5
6
7
8
9

into

123
456
789

I've seen examples with awk using a[something]=a[something] but I can't make it work. Can anyone help please?



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: September 21, 2009 at 07:49:43 Pacific
Reply:

One way is to use awk's modulo operator:

#!/bin/bash

awk ' {
if(NR % 3 == 0 )
   printf("%s\n", $0)
else
   printf("%s", $0)
} ' datafile.txt


0
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Split one column into three with awk

Compare files with AWK www.computing.net/answers/programming/compare-files-with-awk/15182.html

calculation help www.computing.net/answers/programming/calculation-help/4906.html

calculation help www.computing.net/answers/programming/calculation-help/4900.html