Copy column string and put in different column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy column string and put in different column
# 1  
Old 02-28-2012
Copy column string and put in different column

Hello

Here is my input:

Code:
SU3902 SU3902A NS29C (10) (00) Q1J1 0
SU3902 SU3902B VLR05 (20) (02) Q2H1 4
SU3902 SU3902C NBR22 (30) (06) Q3R5 8
SU3904 SU39047 NSV19 (11) (09) Q4k6 2
SU3904 SU39048 LB231 (12) (05) Q5k1 6
SU3904 SU39049 11VLT (13) (08) Q10C1 10
SU3904 SU3904A 25R05 (15) (06) Q12G1 0
SU3904 SU3904B TR236 (19) (54) Q7Y1 4
SU3904 SU3904C NN255 (28) (15) Q3Z5 25

Output:

Code:
SU3902 SU3902A NS29C (10) (00) 1 Q1J1 0
SU3902 SU3902B VLR05 (20) (02) 2 Q2H1 4
SU3902 SU3902C NBR22 (30) (06) 3 Q3R5 8
SU3904 SU39047 NSV19 (11) (09) 4 Q4k6 2
SU3904 SU39048 LB231 (12) (05) 5 Q5k1 6
SU3904 SU39049 11VLT (13) (08) 10 Q10C1 10
SU3904 SU3904A 25R05 (15) (06) 12 Q12G1 0
SU3904 SU3904B TR236 (19) (54) 7 Q7Y1 4
SU3904 SU3904C NN255 (28) (15) 3 Q3Z5 25


just copy number from column 6 after Q and put it before Column 6

Thanks
# 2  
Old 02-28-2012
awk

Hi,

Try this,


Code:
nawk '{t=$6;gsub(/[A-Za-z][0-9]$/,"",$6);a=substr($6,2,length($6));$6=a" "t;}1' file




I think you have asked the same kind of question yesterday right??

Cheers,
RangaSmilie
# 3  
Old 02-28-2012
Another way in awk using match function :
Code:
awk '{match($6,/Q[0-9]+/);$6=substr ($6,2,RLENGTH-1) FS $6}1' input

# 4  
Old 02-28-2012
using sed

Code:
$ sed 's/\(.*)\) \([A-Z]\)\([0-9]*\)\(.*\)/\1 \3 \2\3\4/' input.txt
SU3902 SU3902A NS29C (10) (00) 1 Q1J1 0
SU3902 SU3902B VLR05 (20) (02) 2 Q2H1 4
SU3902 SU3902C NBR22 (30) (06) 3 Q3R5 8
SU3904 SU39047 NSV19 (11) (09) 4 Q4k6 2
SU3904 SU39048 LB231 (12) (05) 5 Q5k1 6
SU3904 SU39049 11VLT (13) (08) 10 Q10C1 10
SU3904 SU3904A 25R05 (15) (06) 12 Q12G1 0
SU3904 SU3904B TR236 (19) (54) 7 Q7Y1 4
SU3904 SU3904C NN255 (28) (15) 3 Q3Z5 25

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to copy a column of multiple files and paste into new excel file (next to column)?

I have data of an excel files as given below, file1 org1_1 1 1 2.5 100 org1_2 1 2 5.5 98 org1_3 1 3 7.2 88 file2 org2_1 1 1 2.5 100 org2_2 1 2 5.5 56 org2_3 1 3 7.2 70 I have multiple excel files as above shown. I have to copy column 1, column 4 and paste into a new excel file as... (26 Replies)
Discussion started by: dineshkumarsrk
26 Replies

2. Shell Programming and Scripting

Locate the files in the first column and copy the files in 2nd column

#cat data.txt file1 folder1 file2 thisforfile2 file3 thisfolderforfile3 lata4 folder4 step 1: create the folder first in column 2 for i in `awk '{print $2}' data.txt` do mkdir /home/data/$i done step 2: locate the files in column1 and stored them into a file for i in... (17 Replies)
Discussion started by: kenshinhimura
17 Replies

3. Shell Programming and Scripting

Column 2 string count in Column 3

My I/p is Col1|Col2|Col3 2116209997932|POSIX INC|POSIX 2116209997933|POSIX INC|POSIX 2116210089479|POSIX INC|POSIX 2116210180502|POSIX INC|POSIX 2116210512279|POSIX INC|Aero 2116210516838|POSIX INC|POSIX 2116210534342|POSIX INC|postal 2116210534345|POSIX INC|postal ... (6 Replies)
Discussion started by: nikhil jain
6 Replies

4. Shell Programming and Scripting

Use a string in one column to get the largest or the smallest of another column

I have data that looks like this: chr1 mm9_knownGene exon 155747075 155747189 0.000000 + . gene_id "Glul"; transcript_id "uc007daq.1"; chr1 mm9_knownGene exon 155750064 155750076 0.000000 + . gene_id "Glul";... (3 Replies)
Discussion started by: pbluescript
3 Replies

5. UNIX for Advanced & Expert Users

Copy a column to another column in UNIX fixedwidth file

Hi All, I have a fixedwidth file of length 3000. Now i want to copy a column of 4 chars i.e( length 1678-1681) to column 1127 – 1171 to the same file. Please let me know how can i achive using a single command in fixed width file. Also source column length is 4 chars and target column length... (4 Replies)
Discussion started by: kiranparsha
4 Replies

6. Shell Programming and Scripting

Help on Script of Copy String from column

Hello, My DATA: PLOKIJ1234G 12 13 14 15 PLOKIJ1234E 12 13 14 15 PLOKIJ1234F 12 22 33 44 IJNUHB12346 55 66 77 88 IJNUHB12347 32 34 45 67 IJUHU345D 23 23 22 33 IJUHYG23E 11 24 23 23 IJUHYG23F 77 88 99 00 output: PLOKIJ1234 PLOKIJ1234G 12 13 14 15 PLOKIJ1234... (11 Replies)
Discussion started by: asavaliya
11 Replies

7. UNIX for Dummies Questions & Answers

Copy column to another column in unix

Dear Gurus, I have a unix file 2 columns (# delimited) with the following data: ZTXX_CTBR1-ZBRAN1#ZTXX_CTBR1-ZBRAN_DESC# 01#CASH & CARRY# 02#DRUGSTORE - RX# 04#SUPERMARKET# 05#HYPERMARKET# 17#DRUGSTORE - NO RX# I would like to have a code that will do 2 things: 1. Delete the header... (16 Replies)
Discussion started by: chumsky
16 Replies

8. Shell Programming and Scripting

Copy the data column to adjacent column

Hi, i have file which contains only one record like below a|b|c|.... The no of columns is not known. The expected output is as below: a|a|b|b|c|c|... Please provide me your suggestions. OS: unix Thanks, Selva (7 Replies)
Discussion started by: bharathappriyan
7 Replies

9. Shell Programming and Scripting

how to put it in a column

Simple question ..What is the easiest way to list my output in a column like so dddd dddd dddd dddd output dddd dddd dddd dddd Thanks (3 Replies)
Discussion started by: bombcan
3 Replies

10. UNIX for Advanced & Expert Users

extracting/copy a column into a new column

Hello, Anybody out there knows how to copy a column data into a blank column using unix command? Thanks (1 Reply)
Discussion started by: folashandy
1 Replies
Login or Register to Ask a Question