transposing rows to columns
Hi all,
I have the following problem, I generated a file with 253 columns and 11323 rows, I want to generate separate files from each row, at the same time I need every file to be a single-column file. I tried with the following script to transpose both, the main matrix and the single row files that I also generated Code:
#! /bin/sh Luis ------------- Working on Ubuntu 12.04 LTS |
Hi.
Quote:
|
With this InFile ...
Code:
apple red honda panama Code:
#!/bin/bash out.txt1 ... Code:
apple Code:
banana This code copes with tab characters which may be in the input file. All files (InFile, code, and the multiple OutFiles) will be in the same folder. On my machine all files have similar names, including dbm712. You would specify complete file identifiers appropriate to your application. Daniel B. Martin |
No need to get all matrix-y here. All you really want to do is convert the space delimiters on each line into newlines, and print each line to a separate file.
Code:
awk '{ for (i=1;i<=NF;i++){ print $i > "file" NR ".txt" } }' infile.txt And just to round it out, here's a quick bash loop too: Code:
n=1 |
Even less need actually:
Code:
awk '{$1=$1;print > "file" NR ".txt"}' OFS="\n" file |
I knew it! Once again, grail comes through with the shortest solution.
Let me guess. Trying to print $0 alone fails, because it stores the original line intact, field separators and all. But if you modify the line in any way, then the OFS setting will apply to it. So just set one field to itself and suddenly it starts printing with newlines between them. Now why didn't I think of that? :doh: |
It's ok David ... you get the kudos for all the other stuff .. I just get the awk one's now and then ;)
|
All times are GMT -5. The time now is 09:36 AM. |