By using AWK can I convert matrice shaped data to a row ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting By using AWK can I convert matrice shaped data to a row ?
# 8  
Old 10-05-2010
Code:
$ ruby  -ane '$F.each{|x| puts x}' file

This User Gave Thanks to kurumi For This Post:
# 9  
Old 10-05-2010
Code:
xargs -n1 < infile

Code:
awk '$1=$1' OFS="\n" infile

Code:
tr '[ \t]' '[\n*]' < infile

This User Gave Thanks to Scrutinizer For This Post:
# 10  
Old 10-05-2010
great codes... all of them works well... thank you...

---------- Post updated at 03:10 PM ---------- Previous update was at 02:59 PM ----------

Code:
awk '$1=$1' OFS="\n" infile

I have hundreds of lines and columns. It is seen that the fastest command is above.


thank you all

Last edited by Scott; 10-05-2010 at 02:35 PM.. Reason: Code tags
# 11  
Old 10-05-2010
Code:
 tr ' ' '\n' < inputfile

# 12  
Old 10-05-2010
suppose that we have column data
1
2
3
4
5
6
.
.
.
how can I generate a new column data by summing the elements of 3 by 3 that gives a result as follows

6
15
.
.
.

THANK YOU
# 13  
Old 10-05-2010
something like this:

Code:
awk 'NR%3==0 { sum = sum + $0 ; print sum ; sum = 0 ; next } { sum = sum + $0 }' file_name

# 14  
Old 10-05-2010
Assuming that the number of lines in file is a multiple of 3:
Code:
sed 'N;N;y/\n/+/' file | bc

Code:
paste -d+ - - - < file | bc

For a more general case (the final number will be the sum of 1 or 2 lines if that's all that remains):
Code:
paste -d+ - - - < file | sed '$s/++*$//' | bc


Last edited by alister; 10-05-2010 at 07:42 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get row data printed in column using awk?

Hi team, I have below sample file. $ cat sample dn: MSISDN=400512345677,dc=msisdn,ou=NPSD,serv=CSPS,ou=servCommonData,dc=stc structuralObjectClass: NphData objectClass: NphData objectClass: MSISDN entryDS: 0 nodeId: 35 createTimestamp: 20170216121047Z modifyTimestamp: 20170216121047Z... (3 Replies)
Discussion started by: shanul karim
3 Replies

2. Shell Programming and Scripting

Convert Data from Column to Row

Hi FileA.txt E_TIM 16, ETE 15, EOND 26, EEC 81, E_1 un, E_2 un, E_3 un, E_4 284, E_TIM 17, ETE 15, EOND 29, EEC 82, E_1 un, E_2 un, E_3 un, E_4 249, (6 Replies)
Discussion started by: asavaliya
6 Replies

3. Shell Programming and Scripting

Convert columns to row using awk

Hi I need to convert some columns form a html file to rows. I do manage to make it works without help (some proud :) ) For some reason the offline status is not in bold, so I do need to remove the <b> tag from the other field to make this to work. All fields are not needed, so I test and... (5 Replies)
Discussion started by: Jotne
5 Replies

4. UNIX for Advanced & Expert Users

Convert column data to row data using shell script

Hi, I want to convert a 3-column data to 3-row data using shell script. Any suggestion in this regard is highly appreciated. Thanks. (4 Replies)
Discussion started by: sktkpl
4 Replies

5. UNIX for Dummies Questions & Answers

awk: convert column to row in a specific way

Hi all! I have this kind of output: a1|b1|c1|d1|e1 a2|b2|c2 a3|b3|c3|d3 I would like to transpose columns d and e (when they exist) in column c, and under the row where they come from. Then copying the beginning of the row. In order to obtain: a1|b1|c1 a1|b1|d1 a1|b1|e1 a2|b2|c2... (1 Reply)
Discussion started by: lucasvs
1 Replies

6. Shell Programming and Scripting

How to convert 2 column data into multiple columns based on a keyword in a row??

Hi Friends I have the following input data in 2 columns. SNo 1 I1 Value I2 Value I3 Value SNo 2 I4 Value I5 Value I6 Value I7 Value SNo 3 I8 Value I9 Value ............... ................ SNo N (1 Reply)
Discussion started by: ks_reddy
1 Replies

7. Shell Programming and Scripting

Convert row data to column data

Hi Guys, I have a file as follows: a 1 b 786 c 90709 d 99 a 9875 b 989 c 887 d 111 I want: a 1 9875 b 786 989 (3 Replies)
Discussion started by: npatwardhan
3 Replies

8. Shell Programming and Scripting

How to insert data befor some field in a row of data depending up on values in row

Hi I need to do some thing like "find and insert before that " in a file which contains many records. This will be clear with the following example. The original data record should be some thing like this 60119827 RTMS_LOCATION_CDR INSTANT_POSITION_QUERY 1236574686123083rtmssrv7 ... (8 Replies)
Discussion started by: aemunathan
8 Replies
Login or Register to Ask a Question