Help with reformat/transpose word


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with reformat/transpose word
# 1  
Old 07-29-2016
Help with reformat/transpose word

Input File
Code:
SAFAS 6000 5
ASGAFAWQ 6022 8
SGAFAWQ 6023 7
GGC 16023 3
.
.

Output File
Code:
S 6000
A 6001
F 6002
A 6003
S 6004 
A 6022
S 6023
G 6024
A 6025
F 6026
A 6027
W 6028
Q 6029
S 6023
G 6024
A 6025
F 6026
A 6027
W 6028
Q 6029
G 16023
G 16024
C 16025
.
.

First column is the word; second column is the start position of first word in first column; third column is the total number of words in first column.

I would like to reformat/transpose all the word in first column into new line and print out it corresponding position.

Thanks again for any advice Smilie
# 2  
Old 07-29-2016
You seem to mix up rows and colums?

Any attempts/ideas/thoughts from your side?
This User Gave Thanks to RudiC For This Post:
# 3  
Old 07-29-2016
Hi RudiC,

Yup. You're right.
So sorry about that.

I just edit my thread.
# 4  
Old 07-29-2016
something along these lines:
Code:
awk '{ for(i=0; i<$3; i++) print substr($1,i+1,1), $2+i}' myFile

This User Gave Thanks to vgersh99 For This Post:
# 5  
Old 07-29-2016
You didn't answer my question for your own efforts. Anyhow, try
Code:
awk '{for (i=0; i<$3; i++) print substr($1, i+1, 1), $2+i}' file

This User Gave Thanks to RudiC For This Post:
# 6  
Old 07-29-2016
Thanks again, R. Singh Smilie

I just do a few manual checking.
It seems worked perfectly with all the different case and scenario Smilie

Really many thanks for your fast advice and sharing.

---------- Post updated at 11:10 AM ---------- Previous update was at 11:06 AM ----------

Thanks, RudiC.
Sorry I fail to try with own method Smilie

What I think at first place is split the file into two (First column at file 1 and Second column at file 2).
For first 1, do the reformat of word at column 1.
For first 2, print out the corresponding position based on start word and word length at column 1.

Paste both file together after then Smilie
My method seems not so efficient.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parse and reformat

Trying to parse column C ($3) of the attached file (104 rows). The data is in the below format all in a string. Each string would be a separate row with the data in column A ($1) and column B ($2) being the header. All the data is in seperate columns as well. Thank you :). ACTA 59... (9 Replies)
Discussion started by: cmccabe
9 Replies

2. Shell Programming and Scripting

Help with reformat data structure

Input file: bv|111259484|pir||T49736_real_data bv|159484|pir||T9736_data_figure bv|113584|prf|T4736|truth bv|113584|pir||T4736_truth Desired output: bv|111259484|pir|T49736|real_data bv|159484|pir|T9736|data_figure bv|113584|prf|T4736|truth bv|113584|pir|T4736|truth Once the... (8 Replies)
Discussion started by: perl_beginner
8 Replies

3. Shell Programming and Scripting

reformat HHMMSSmmm into HH:MM:SS.mmm

I have a bunch of logs where the timestamp hours, minutes, seconds and milliseconds all together without a visual delimiter, as below 123045000 I'd prefer to see more easier to read familiar format, as 12:30:45.000 I came up with this ugly echo '123045000'|awk '{print... (2 Replies)
Discussion started by: migurus
2 Replies

4. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

5. Shell Programming and Scripting

Reformat a file

I have a csv file with 11 columns. The first columns contains the User Id. One User id can have multiple sub Id. The value of Sub Id is in column 10. 100026,captjason@hawaii.rr.com ,jason ,wolford ,1/16/1969, ,US, ,96761 ,15 ,seg_id 100026,captjason@hawaii.rr.com ,jason ,wolford ,1/16/1969,... (3 Replies)
Discussion started by: r_t_1601
3 Replies

6. Shell Programming and Scripting

Please help me reformat this file

I am working with a file of the form; 4256 7726 1 6525 716 1 7626 0838 1 8726 7623 2 8625 1563 2 1662 2628 3 1551 3552 3 1542 7984 ... (3 Replies)
Discussion started by: digipak
3 Replies

7. Shell Programming and Scripting

Reformat Data (Perl)

I am new to Perl. I need to reformat a data file as the last part of a script I am working on. I am stuck on this. Here is the current format: CUSTOMER Filename 09/04/07-08:49 CUSTOMER Filename 09/04/07-08:52 CUSTOMER Filename 09/04/07-08:52 CUSTOMER2 Filename 09/04/07-08:49 CUSTOMER2... (3 Replies)
Discussion started by: flood
3 Replies

8. UNIX for Advanced & Expert Users

reformat ps output

I often use "ps -ef" command to list all running processes. Now i want to customize the output to show only 2 parts: CMD and UID as below: /bin/bash /usr/bin/run-parts /etc/cron.weekly root /usr/sbin/httpd apache /usr/sbin/httpd apache /usr/sbin/httpd apache I use ps -ef | awk '{print $8"... (3 Replies)
Discussion started by: fongthai
3 Replies

9. UNIX for Dummies Questions & Answers

Date Reformat

Hello, I have a .CSV file with 10+ datetime columns. The way the data is stored in these columns are - 4/4/2006 3:45:30 PM I want the single digits to be left padded with a zero so the above looks like 04/04/2006 03:45:30 PM As the dates and times are different throughout the file... (2 Replies)
Discussion started by: F-1
2 Replies

10. Shell Programming and Scripting

reformat the file

Hi all, I ran into this problem, hope you can help I have a text file like this: Spriden ID First Name Last Name Term Code Detail Code Amount Trans Date Description ... (3 Replies)
Discussion started by: CamTu
3 Replies
Login or Register to Ask a Question