How to insert alternative columns and sort text from first column to second?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to insert alternative columns and sort text from first column to second?
# 1  
Old 07-09-2010
How to insert alternative columns and sort text from first column to second?

Hi Everybody,
I am just new to UNIX as well as to this forum. I have a text file with 10,000 coloumns and each coloumn contains values separated by space. I want to separate them into new coloumns..the file is something like this


as ad af 1 A
as ad af 1 D
...
...
1 and A are in one coloumn and are separated by space. so I want to have a file like

as ad af 1 A in which 1 and A are in different coloumns. I have 10,000 coloumns like this.

Can somebody help me with this!
Thanks a lot

Last edited by Unilearn; 07-09-2010 at 06:35 AM.. Reason: Not clearly stated
# 2  
Old 07-09-2010
Could you please post an example of the desired output?
# 3  
Old 07-09-2010
thanks for the reply radoulov,
my original file is like this..

1st & 2nd columns contain text but from 3rd to last columns contain digits.
example,
ast bdf 1_2 1_1 2_2
so, in 1_2, the "_" is space in my file. I want to have them separated in two coloumns like 1 2.

In excel I can actually insert a coloumn between two coloums and use the option of "text to columns" to separate them. However, my file contains morethan 10,000 coloumns. So, I was wondering whether we can use of the UNIX script to do it.
I am really sorry if I am not clear enough.
# 4  
Old 07-09-2010
And what is the character between ast and bdf and between bdf and 1? A tab?

Last edited by radoulov; 07-09-2010 at 08:30 AM..
# 5  
Old 07-09-2010
yes it is tab separated!
# 6  
Old 07-09-2010
Try this:

Code:
perl -i.bck  -ple's/(\d) +/\1\t/g' infile

This User Gave Thanks to radoulov For This Post:
# 7  
Old 07-09-2010
Code:
cat file | awk '{ split($0,temp," "); printf("%s\t%s\t%s\t%s\t%s\n",temp[1],temp[2],temp[3],temp[4],temp[5])}'


Last edited by radoulov; 07-09-2010 at 09:22 AM.. Reason: Please use code tags!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert Columns before the last Column based on the Count of Delimiters

Hi, I have a requirement where in I need to insert delimiters before the last column of the total delimiters is less than a specified number. Say if the delimiters is less than 139, I need to insert 2 columns ( with blanks) before the last field awk -F 'Ç' '{ if (NF-1 < 139)} END { "Insert 2... (5 Replies)
Discussion started by: arunkesi
5 Replies

2. Shell Programming and Scripting

Seperated by columns, merge in a file, sort them on common column

Hi All, I have 4 files in below format. I took them as an example. File 1: Cut from position 1-4 then 6-7 then 8-14 then rest left and make them as columns in one new file. Inserting character H to the initial of all line like HCTOT. CTOT 456787897 Low fever CTOR 556712345 High fever... (2 Replies)
Discussion started by: Mannu2525
2 Replies

3. Shell Programming and Scripting

How to sort a text file if certain columns are blank?

Dear all, I am trying to sort a text file based on column 3, 10, 11 and 12. But certain column are blank for some lines. Column 3 has to be in ascending order after sorting. Part of my input file is as follows: CN727990 1 A01 4703 5083 73.28 - A_scaffold000011 4365605 4365985 73.28 +... (10 Replies)
Discussion started by: huiyee1
10 Replies

4. Shell Programming and Scripting

Insert space in specific column among many columns

Hello, I have some problem in inserting the space for the pairs of columns. I have the input file : I used this code below in replacing it using space in specific column (replace space in each two columns) sed -e "s/,/ /2" -e "s/,/ /3" inputfile Output showed : However, I have many... (3 Replies)
Discussion started by: awil
3 Replies

5. Shell Programming and Scripting

Insert text into specific column

I have the following data: Dec 24 11:31:10 0000008b 9911662486 Answered Price SGD 0.003 PERIOD: 0 m 6 s Dec 24 11:21:42 00000086 9911662486 Answered Price SGD 0.001 PERIOD: 0 m 2 s Dec 20 15:34:28 00000004 9911662486 Answered Price SGD 0.007 PERIOD: 0 m 12 s Dec 20 18:42:30 0000017b... (6 Replies)
Discussion started by: alegnagrp
6 Replies

6. Shell Programming and Scripting

sed - insert text if column empty

Hi, I want to insert the text 'Unknown' in 2 specific columns in a csv file (actually | separated) if the column is blank. Its always the same columns. I have tried using sed: sed "s/||/|Unknown|/g" but there are occasion where other fields are blank and they need to be left blank. This... (4 Replies)
Discussion started by: ksexton
4 Replies

7. UNIX for Dummies Questions & Answers

Sort text file starting at column X

Hello everyone! As the heading reads, I would like to sort the lines of a text file, starting at a specific column (i.e. skip the first X characters of each line). What I’m actually trying to sort is the md5 sums file of a directory. Every time I copy a new file to that directory, I perform... (3 Replies)
Discussion started by: iznogoud
3 Replies

8. Shell Programming and Scripting

sort each column of text file alone

Hello , i have a text file like this 1 a1 ,AB ,AC ;AD ,EE 2 a2 ,WE ;TR ,YT ,WW 3 a3 ;AS ,UY ;RF ,YT i want to sort this text file based on each row , and excluding 2nd column from the sorting and not taking the comma or ; into consideration in the sorting, so it will become like this... (12 Replies)
Discussion started by: shelladdict
12 Replies

9. UNIX for Dummies Questions & Answers

Insert text in datafile with uneven columns

Dear Unix Gurus, I have a dataset consisting of a number of uneven columns. What I would like to do is fill up the missing rows with an arbitrary text of fixed value so that all columns now have an equal number of rows. for example, in the sample datafile below... 1.0 1.3 0.25 2.2 2.0... (2 Replies)
Discussion started by: tintin72
2 Replies

10. Shell Programming and Scripting

insert text into column

Hello! I have a text file containing some text : : : bla other text : : : bla any text : : : bla containing 3 columns separated by the ':' sign. Now i want to insert 'this' in the 2nd line after the 2nd column-deliminiter (i.e. into 3rd column), like some text : : : bla other text :... (1 Reply)
Discussion started by: knoxo
1 Replies
Login or Register to Ask a Question