ordering a data file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ordering a data file
# 8  
Old 04-01-2010
And what can I do if the file is like this one?

Quote:
_1.012E+01_2.102E+04_3.222E+03_4.100E+02
-1.144E+02-2.489E-02_5.444E+01-3.122E-03
-3.566E+00_7.455E+04
_2.562E+01_2.892E+04_3.542E+03_4.654E+02
-1357E+02-2.321E-02_5.654E+01-3.789E-03
-4.326E+03_7.834E+00
i.e:
Quote:
1stelement2ndelement3rdelement4rdelement
5thelement6thelement7thelement8thelement
9thelement10thelement
11thelement12thelement13thelement...
...
I need the output in a single column without empty lines, I tried with the scripts you suggested me something goes wrong.

I need this:

Quote:
1stelement
2ndelement
3rdelement
4rdelement
5thelement
6thelement
7thelement
8thelement
9thelement
10thelement
11thelement
12thelement
13thelement
...
Can anybody help me?
# 9  
Old 04-01-2010
use below for general cases as yours:-

Code:
awk '{for (i=1;i<=length($0);i+=10) {s=substr($0,i,10) ; print s} }' infile.txt

SmilieSmilieSmilie
# 10  
Old 04-01-2010
thanks! really useful!
# 11  
Old 04-01-2010
better one. which will work if the element length is not equal to 10 as well (variable length of elements).

Code:
perl -wple 's/([^E])([-_])/$1\n$2/g;'  infile.txt

SmilieSmilieSmilie

Last edited by ahmad.diab; 04-01-2010 at 01:25 PM..
# 12  
Old 04-01-2010
another question (I hope my last one):

I have a file like this:

Quote:
z1
z2
z3
z4
...
z10000
where zn is some number.
but I need it in the following order:
Quote:
z1
z101
z201
z301
...
z9801
z9901
z2
z102
z202
z302
...
z9902
z3
z103
z203
z303
...
z9903
z4
z104
...
...
z9999
z100
z200
z300
...
z10000
I hope I have explained clearly
# 13  
Old 04-01-2010
using perl:-


Code:
perl -wlne 'push @a,[ substr($_,-1,1),$_];END{$,="\n" ;print map {$_->[1]} sort {$a->[0] <=> $b->[0]}  @a}' infile.txt

SmilieSmilieSmilie
# 14  
Old 04-01-2010
solved! i did:

Code:
let lc=1
while [ $lc -lt 100 ]; do
awk 'NR%100==lc' lc=$lc input >> output
let lc=$lc+1
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash - re-ordering list of parameters

Hello. I have a script that writes parameters in alphabetic order. But I have a parameter which have 3 lines. There is no continuation character ( '\' ). Each of the three lines finish with 'cr'. But line 2 and 3 of the concerning parameter start with a tab char (but should be one or more... (7 Replies)
Discussion started by: jcdole
7 Replies

2. Shell Programming and Scripting

Ordering batch number

Hi, Could some one please help to order the batch number in sequence. I will be getting bunch of files with batch number in folder1 which are not in sequence. I need to move all files from folder1 to folder2 with batch number in sequence. Header record looks like PROCESS1... (8 Replies)
Discussion started by: zooby
8 Replies

3. Shell Programming and Scripting

Ordering Folders having Date as Names

Hi All, I have directories under /development/arun/weekly/ 20120421 20120414 . . . . I need to arrange these directories in descending order. folder name with recent date will be on top and then others. (1 Reply)
Discussion started by: Arun Mishra
1 Replies

4. Shell Programming and Scripting

Random ordering

1 2 4 5 3 I would like to use a script so that i can randomly rearrange these numbers such as 3 5 2 4 1 Thanks! (3 Replies)
Discussion started by: johnkim0806
3 Replies

5. Shell Programming and Scripting

ordering

file1 1 SNP2 3 1 SNP3 3 1 SNP5 4 2 SNP1 4 2 SNP4 4 file2 SNP1 1 1 1 SNP5 5 5 5 SNP4 4 4 4 SNP2 2 2 2 SNP3 1 1 1 desired output (1 Reply)
Discussion started by: johnkim0806
1 Replies

6. Shell Programming and Scripting

Re ordering lines - Awk

Is it possible to re-order certain rows as columns (of large files). Few lines from the file for reference. input Splicing Factor: Tra2beta, Motif: aaguguu, Cutoff: 0.5000 Sequence Position Genomic Coordinate K-mer Score 97 chr1:67052604 uacuguu 0.571 147... (3 Replies)
Discussion started by: quincyjones
3 Replies

7. Shell Programming and Scripting

Re-ordering data

input Predictions for job: 1299399580 ********************************************** gg18_qqq10_100017878_100017978_- ============================================================================== zzz Factor: XXX, ttt: crsmsgw, Cutoff: 0.6429 seqe Position fff Coordinate K-mer Score ... (3 Replies)
Discussion started by: quincyjones
3 Replies

8. Homework & Coursework Questions

word ordering problem HELP please (linux)

Hi guys I need you ,please help me i have to do this for tomorow and i don't understand how to do Q1 : Order the words of RADIO.txt by frequency Q2 : Order the words of RADIO.txt in alphabétique order Q3 : Order the words of RADIO.txt par ordre "rhymique" (exemple, put togeder words which are... (1 Reply)
Discussion started by: Lili
1 Replies

9. Shell Programming and Scripting

File ordering by portion of filename

Hi, Lets say I have a few xml files: 1234567894.xml abc_1234567895.xml abc_000_1234567890.xml abc_0000000_1234567893.xml 684_abc_000_1234567899.xml The naming convention of the files is: xxxxx_timestamp.xml OR timestamp.xml where x can be anything and I would like to order them by... (4 Replies)
Discussion started by: Leion
4 Replies

10. Shell Programming and Scripting

proper ordering of o/p values

Hi, Below is my script which creates a file: #!/bin/sh if then echo "Enter bill period " echo "Syntax: sh cpd.sh G08" exit fi sqlplus uname/pwd@dbname <<EOF set WRAP off set FEEDBACK off set PAGESIZE 0 set VERIFY off (14 Replies)
Discussion started by: ss_ss
14 Replies
Login or Register to Ask a Question