Relocation strings using awk/sed from a index file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Relocation strings using awk/sed from a index file
# 8  
Old 05-11-2016
"\t" is a <TAB> char:
Code:
awk 'BEGIN {print "\t"}' | hd
00000000  09 0a                                             |..|

, so something else must be going wrong there.
# 9  
Old 05-11-2016
Is anybody help me to fix the last step? I need a tab or a space between strings. I tried many ways but did not work. Thank you in advance.



My current code:
Code:
awk '
NR==FNR         {T[$2] = $1
                 MX = $1
                 next
                }
$1 in T         {IX = T[$1]
                }
                {P[IX, (FNR+3)%4] = P[IX, (FNR+3)%4] $0
                }
END             {for (i=0; i<=MX; i++) for (j=0; j<4; j++) print P[i, j]
                }
' index.txt source.txt


My current output:
Code:
path_sparc_ifu_dec_in_3826path_sparc_ifu_dec_in_4349
dtu_inst_d[14]dtu_inst_d[18]
dec_fcl_rdsr_sel_pc_ddec_swl_rdsr_sel_thr_d
0.86640.795429
path_sparc_ifu_dec_in_2374path_sparc_ifu_dec_in_4011
dtu_inst_d[13]dtu_inst_d[13]
dec_dcl_cctype_d[2]ifu_exu_useimm_d
0.9389140.843643
path_sparc_ifu_dec_in_3078
dtu_inst_d[12]
ifu_exu_shiftop_d[2]
0.915818

# 10  
Old 05-12-2016
Quote:
Originally Posted by jypark22
Is anybody help me to fix the last step? I need a tab or a space between strings. I tried many ways but did not work. Thank you in advance.



My current code:
Code:
awk '
NR==FNR         {T[$2] = $1
                 MX = $1
                 next
                }
$1 in T         {IX = T[$1]
                }
                {P[IX, (FNR+3)%4] = P[IX, (FNR+3)%4] $0
                }
END             {for (i=0; i<=MX; i++) for (j=0; j<4; j++) print P[i, j]
                }
' index.txt source.txt


My current output:
Code:
path_sparc_ifu_dec_in_3826path_sparc_ifu_dec_in_4349
dtu_inst_d[14]dtu_inst_d[18]
dec_fcl_rdsr_sel_pc_ddec_swl_rdsr_sel_thr_d
0.86640.795429
path_sparc_ifu_dec_in_2374path_sparc_ifu_dec_in_4011
dtu_inst_d[13]dtu_inst_d[13]
dec_dcl_cctype_d[2]ifu_exu_useimm_d
0.9389140.843643
path_sparc_ifu_dec_in_3078
dtu_inst_d[12]
ifu_exu_shiftop_d[2]
0.915818

In post #1 in this thread, you showed us index.txt and source.txt files that had leading spaces on every line in both files. To get the output you are showing above, we have to assume that those spaces do not appear in source.txt.

If you want a tab in the output separating the text from various lines in source.txt, change the line in your code marked in red above in your script from:
Code:
                {P[IX, (FNR+3)%4] = P[IX, (FNR+3)%4] $0

to:
Code:
                {P[IX, (FNR+3)%4] = P[IX, (FNR+3)%4] "\t" $0

# 11  
Old 05-12-2016
I am assuming your executing code from post #3.
modify below line from
Code:
P[IX, (FNR+3)%4] = P[IX, (FNR+3)%4] $0

to
Code:
P[IX, (FNR+3)%4] = P[IX, (FNR+3)%4]"\t"$0

# 12  
Old 05-12-2016
Thank you so much, Don.

It is resolved when I added "\t" before $0.

Best,

Jaeyoung
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding sequential index to duplicate strings

I have a text file in the following format >Homo sapiens KQKCLYNLPFKRNLEGCRERCSLVIQIPRCCKGYFGRDCQACPGGPDAPCNNRGVCLDQY SATGECKCNTGFNGTACEMCWPGRFGPDCLPCGCSDHGQCDDGITGSGQCLCETGWTGPS CDTQAVLPAVCTPPCSAHATCKENNTCECNLDYEGDGITCTVVDFCKQDNGGCAKVARCS... (2 Replies)
Discussion started by: jerrild
2 Replies

2. UNIX for Beginners Questions & Answers

Use strings from nth field from one file to match strings in entire line in another file, awk

I cannot seem to get what should be a simple awk one-liner to work correctly and cannot figure out why. I would like to use patterns from a specific field in one file as regex to search for matching strings in the entire line ($0) of another file. I would like to output the lines of File2 which... (1 Reply)
Discussion started by: jvoot
1 Replies

3. Shell Programming and Scripting

Relocation strings

Hi all, I would like to relocate strings based on the index number. Index numbers are shown on the first column, the strings are shown on the second column. 1 path_sparc_ifu_dec_104 1 path_sparc_ifu_dec_105 2 path_sparc_ifu_dec_63 2 ... (3 Replies)
Discussion started by: jypark22
3 Replies

4. Programming

How to replace the complex strings from a file using sed or awk?

Dear All, I am having a requirement to find the difference between 2 files and generate a discrepancy report out of it as an html page. I prefer using diff -y file1 file2 since it gives user friendly layout to know any discrepancy in the record and unique records among the 2 file. Here's how it... (12 Replies)
Discussion started by: Badhrish
12 Replies

5. Shell Programming and Scripting

awk or sed script to remove strings

Below am trying to separate FA-7A:1, In output file it should display 7A 1 Command am using Gives same output as below format: 22B7 10000000c9720873 0 22B7 10000000c95d5d8b 0 22BB 10000000c97843a2 0 22BB 10000000c975adbd 0 Not showing FA ports as required format... (5 Replies)
Discussion started by: aix_admin_007
5 Replies

6. Shell Programming and Scripting

awk extract certain digits from file with index substr

I would like to extract a digit from $0 starting 2,30 to 3,99 or 2.30 to 3.99 Can somebody fix this? awk --re-interval '{if($0 ~ /{1}{2}/) {print FILENAME, substr($0,index($0,/{1}{2}/) , 4)}}'input abcdefg sdlfkj 3,29 g. lasdfj alsdfjasl 2.86 gr. slkjds sldkd lskdjfsl sdfkj kdjlksj 3,34 g... (4 Replies)
Discussion started by: sdf
4 Replies

7. Shell Programming and Scripting

Replace Strings with sed or awk

Hello i need some help with the usage of sed. Situation : 2 textfiles, file.in , file.out In the first textfile which is called file.in are the words for the substitution. Every word is in a new-line like : Firstsub Secondsub Thridsub ... In the second textflie wich is called file.out is... (5 Replies)
Discussion started by: Kingbruce
5 Replies

8. UNIX for Dummies Questions & Answers

Using awk/sed to extract text between Strings

Dear Unix Gurus, I've got a data file with a few hundred lines (see truncated sample)... BEGIN_SCAN1 TASK_NAME=LA48 PDD Profiles PROGRAM=ArrayScan 1.00 21.220E+00 2.00 21.280E+00 END_DATA END_SCAN1 BEGIN_SCAN2 TASK_NAME=LA48 PDD Profiles 194.00 2.1870E+00 ... (5 Replies)
Discussion started by: tintin72
5 Replies

9. Filesystems, Disks and Memory

why the inode index of file system starts from 1 unlike array index(0)

why do inode indices starts from 1 unlike array indexes which starts from 0 its a question from "the design of unix operating system" of maurice j bach id be glad if i get to know the answer quickly :) (0 Replies)
Discussion started by: sairamdevotee
0 Replies

10. Shell Programming and Scripting

(awk) compare files in dir with an index file

Using awk I have an index file which has been seperated into 5 fields. The first field contains file names. What I need to do is check to see if a file exists in my current directory that is not in the first field of my index file. If its not i print out a message. Please help! (4 Replies)
Discussion started by: xthexonex
4 Replies
Login or Register to Ask a Question