Filter and migrate data from row to column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Filter and migrate data from row to column
# 1  
Old 05-31-2010
Filter and migrate data from row to column

Hello Experts,
I am new in scripting. I would like to filter and migrate data from row to column by awk. Thanks in advance.

For example
FileA
Code:
  abc
  1
  2
  3
  Xyz3
  4
  1
  5
  bcd1

Output :
Code:
 Abc      1    2    3
 Xyz3     4    1    5
 bcd1     3    5    6


Last edited by Scott; 05-31-2010 at 09:17 AM.. Reason: Code tags, please...
# 2  
Old 05-31-2010
Try:
Code:
awk '{ORS=NR%4?FS:RS}1' file

# 3  
Old 05-31-2010
Thanks Franlin52, it's working fine if data is according to fileA but if FileA like
FileA
Code:
abc
1
2
3
5
9
10
Xyz3
4
1
5
3
bcd1
4
1

And need output like

Output :
Code:
Abc	1    2   3  5   9  10
Xyz3	4    1   5  3
bcd1  3    5


Last edited by Scott; 05-31-2010 at 09:17 AM.. Reason: Code tags, please...
# 4  
Old 05-31-2010
This should work as your sample file...
Code:
awk '{printf ($0 ~ /^[A-Za-z]/?RS $0:FS $0)}' infile

This User Gave Thanks to malcomex999 For This Post:
# 5  
Old 05-31-2010
G8 malcomex999 and Thanks to malcomex999 & Franklin52 .

small more help....can you explain me in few words ....I understand only this

Code:
$0 ~ /^[A-Za-z]/?RS

user for search strings and Record Separator but don't understand $0:FS $0

Last edited by Scott; 05-31-2010 at 09:18 AM..
# 6  
Old 05-31-2010
Quote:
Originally Posted by malcomex999
This should work as your sample file...
Code:
awk '{printf ($0 ~ /^[A-Za-z]/?RS $0:FS $0)}' infile

The record sperator RS is missing for the last record.
Code:
awk '{printf "%s" ($0 ~ /^[A-Za-z]/?RS $0:FS $0)} END { print RS }' infile

Using printf without format may give an error if printed data contains % sequence.

From Franklin code :
Code:
awk '{ORS=/^[A-Za-Z]/NR%4?FS:RS}1' file

Jean-Pierre.
This User Gave Thanks to aigles For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Filter Row Based On Max Column Value After Group BY

Hello Team, Need your expertise on following: Here is the set of data: C1|4|C1SP1|A1|C1BP1|T1 C1|4|C1SP2|A1|C1BP2|T2 C2|3|C2SP1|A2|C2BP1|T2 C3|3|C3SP1|A3|C3BP1|T2 C2|2|C2SP2|A2|C2BP2|T1 I need to filter above date base on following two steps: 1. Group them by column 1 and 4 2.... (12 Replies)
Discussion started by: angshuman
12 Replies

2. Shell Programming and Scripting

Column to Row Data.

HI Guys, I have below Input :- X L1 5 Y L1 10 Z L1 15 X L2 20 Y L2 12 Z L2 15 X L3 100 Y L3 Z L3 300 Output:- ID L1 L2 L3 X 5 10 15 Y 20 12 15 Z 100 Null 300 (11 Replies)
Discussion started by: pareshkp
11 Replies

3. 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

4. Shell Programming and Scripting

Filter more data in single column

Hi All, One of my source file column name RelationshipNumber. I need to filter below mentioned records in RelationshipNumber column. RelationshipNumber: S45678 D89763 Y09246579 A91234 If it is available in above mentioned column, then I need to print the entire line from my source... (2 Replies)
Discussion started by: suresh_target
2 Replies

5. 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

6. Shell Programming and Scripting

Sort data from column to row

Hi, I need somebody's help with sorting data with awk. I've got a file: 10 aaa 4584 12 bbb 6138 20 ccc 4417 21 ddd 7796 10 eee 7484 12 fff ... (5 Replies)
Discussion started by: killerbee
5 Replies

7. Shell Programming and Scripting

Moving data from a specified column/row to another column/row

Hello, I have an input file like the following: 11_3_4 2_1_35 3_15__ _16989 Where '_' is a space. The data is in a table. Is there a way for the program to prompt the user for x1,y1 and x2,y2, where x1,y1 is the desired number (for example x=6 y=4 is a value of 4) and move to a desired spot... (2 Replies)
Discussion started by: jl487
2 Replies

8. Shell Programming and Scripting

row to column and position data in to fixed column width

Dear friends, Below is my program and current output. I wish to have 3 or 4 column output in order to accomodate in single page. i do have subsequent command to process after user enter the number. Program COUNT=1 for MYDIR in `ls /` do VOBS=${MYDIR} echo "${COUNT}. ${MYDIR}" ... (4 Replies)
Discussion started by: baluchen
4 Replies

9. 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

10. Shell Programming and Scripting

repeated column data filter and make as a row

I need to get the output in row wise for the repeated column data Ex: Input: que = five ans = 5 que = six ans = 6 Required output: que = five six ans = 5 6 Any body can guide me?"""""" (2 Replies)
Discussion started by: vasanth_vadalur
2 Replies
Login or Register to Ask a Question