Changing data format from column into array


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Changing data format from column into array
# 1  
Old 10-19-2012
Changing data format from column into array

I have a file containing numbers in a column like:

10.5
16.3
15.7
2.3
46.8
3.3
.
.
.

and I was wondering if there was a way to make it show up in an array form like:

10.5 2.3
16.3 46.8
15.7 3.3

Let's say I want to make a new column every 100 values. How can I do that and be able to copy and paste the values into individual cells in MS Excel? If it's not possible, let me know too.

Thank you!
# 2  
Old 10-19-2012
The 'paste' command slides files together, so you just need scripts to select the right and left columns. You too 3 and 3, but then you have ..., so is it 3 or half or ? You can pipe together the two file generators to pipe so there is no delay, temp file space limit or extra i/o overhead.
# 3  
Old 10-19-2012
Oh sorry, those are decimal values. Let me give a better example of what I want to do.

I have a file that contains:

1
2
3
4
5
6
7
8
9

and I want to make a file that contains:

1 2 3
4 5 6
7 8 9

and for me to be able to copy that 3 by 3 array and paste it into a 3 by 3 table in excel.

Are you saying the 'paste' command will make a new file with data from each file displayed side by side? If so, is there a way I can take a file and make new files containing every 100 lines of the original file?

Thanks again.
# 4  
Old 10-19-2012
Code:
awk '{printf $1 (!(NR % cols) ? c="\n" : c=" "); } END {print "";}' cols=3 infile

# 5  
Old 10-19-2012
Sorry, just checking. cols will be the number of entries in each column right? Not the number of columns? And what's the $1 for?
# 6  
Old 10-19-2012
Or you can use the paste command directly (each dash represents a column). You can use the -d option of paste to set the delimiter (default is tab)

Code:
cat yourfile | paste - - -

if yourfile contained
Code:
1
2
3
4
5
6
7
8
9
 
and you did
cat yourfile | paste - - -

Code:
You would get
1       2       3
4       5       6
7       8       9

# 7  
Old 10-19-2012
cols is the number of columns out. $1 is the field one on the input file, as in the example provided.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Presenting data in column format

I have written a script that that takes file names and breaks them apart. File names are : aal_mock.war.deployed AuroralMockService-1.0.war.deployed consumerProfile.war.deployed EbillMock.war.deployed IAMAOGServices.war.deployed IAMPermission.war.deployed... (5 Replies)
Discussion started by: Junaid Subhani
5 Replies

2. Shell Programming and Scripting

Changing values only in 3rd column and 4th column

#cat file testing test! nipw asdkjasjdk ok! what !ok host server1 check_ssh_disk!102.56.1.101!30!50!/ other host server 2 des check_ssh_disk!192.6.1.10!40!30!/ #grep check file| awk -F! '{print $3,$4}'|awk '{gsub($1,"",$1)}1' 50 30 # Output: (6 Replies)
Discussion started by: kenshinhimura
6 Replies

3. UNIX for Dummies Questions & Answers

Des/awk for change format and adding integers in a column of data?

Greetings! I need a quick way to change the format in a table of data Here is an example of the input: 10 72 Value=177 VDB=0.0245 Value4=0,0,171,0 10 274 Value=238 VDB=0.0433 Value4=29,0,205,0 10 312 Value=222 VDB=0.0384 Value4=8,0,190,19 10 540 Value=405 VDB=0.0391 Value4=13,30,153,195... (3 Replies)
Discussion started by: Twinklefingers
3 Replies

4. Shell Programming and Scripting

awk - script help: column to row format of data allignment?

Experts Good day, I have the following data, file1 BRAAGRP1 A2X B2X C2X D2X BRBGRP12 A3X B3X Z10 D09 BRC1GRP2 LO01 (4 Replies)
Discussion started by: rveri
4 Replies

5. Shell Programming and Scripting

Compare 2 files and match column data and align data from 3 column

Hello experts, Please help me in achieving this in an easier way possible. I have 2 csv files with following data: File1 08/23/2012 12:35:47,JOB_5330 08/23/2012 12:35:47,JOB_5330 08/23/2012 12:36:09,JOB_5340 08/23/2012 12:36:14,JOB_5340 08/23/2012 12:36:22,JOB_5350 08/23/2012... (5 Replies)
Discussion started by: asnandhakumar
5 Replies

6. Shell Programming and Scripting

Sort a the file & refine data column & row format

cat file1.txt field1 "user1": field2:"data-cde" field3:"data-pqr" field4:"data-mno" field1 "user1": field2:"data-dcb" field3:"data-mxz" field4:"data-zul" field1 "user2": field2:"data-cqz" field3:"data-xoq" field4:"data-pos" Now i need to have the date like below. i have just... (7 Replies)
Discussion started by: ckaramsetty
7 Replies

7. Shell Programming and Scripting

Convert array data to excel format

I need your help in changing the script I have data has below text file :> cat my_emp Employee array(0) Name : Albert No : 1234 Address: stationstraat City: Utrecht Employee array (1) Name : Kouwen No : 1256 Address: stationstraat City: Amsterdam Employee array (2) Name : Peter... (2 Replies)
Discussion started by: LinuxLearner
2 Replies

8. Shell Programming and Scripting

Changing one column of delimited file column to fixed width column

Hi, Iam new to unix. I have one input file . Input file : ID1~Name1~Place1 ID2~Name2~Place2 ID3~Name3~Place3 I need output such that only first column should change to fixed width column of 15 characters of length. Output File: ID1<<12 spaces>>Name1~Place1 ID2<<12... (5 Replies)
Discussion started by: manneni prakash
5 Replies

9. Shell Programming and Scripting

Format - Inventory Row data into Column - Awk - Nawk

Hi All, I have the following file that has computer data for various pcs in my network... Snap of the file is as follows ******************************************************************************* Serial 123456 Computer IP Address lo0:... (1 Reply)
Discussion started by: aavam
1 Replies

10. Shell Programming and Scripting

changing month in Mmm format to mm FORMAT

i have an variable mydate=2008Nov07 i want o/p as in variable mymonth=11 (i.e nov comes on 11 number month) i want some command to do this for any month without using any loop. plz help me (1 Reply)
Discussion started by: RahulJoshi
1 Replies
Login or Register to Ask a Question