Relocation strings


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Relocation strings
# 1  
Old 04-26-2016
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.

Code:
 1        path_sparc_ifu_dec_104  
 1        path_sparc_ifu_dec_105  
 2        path_sparc_ifu_dec_63  
 2        path_sparc_ifu_dec_92 
 3        path_sparc_ifu_dec_39  
 4        path_sparc_ifu_dec_43  
 4        path_sparc_ifu_dec_71  
 5        path_sparc_ifu_dec_103  
 6        path_sparc_ifu_dec_99  
 7        path_sparc_ifu_dec_55 
 7        path_sparc_ifu_dec_75  
 7        path_sparc_ifu_dec_93


If the index number is 1, corresponding strings are placed on the first row. On the same time, the index number is removed.


Desired output is:
Code:
path_sparc_ifu_dec_104  path_sparc_ifu_dec_105  
path_sparc_ifu_dec_63  path_sparc_ifu_dec_92 
path_sparc_ifu_dec_39  
path_sparc_ifu_dec_43  path_sparc_ifu_dec_71  
path_sparc_ifu_dec_103  
path_sparc_ifu_dec_99  
path_sparc_ifu_dec_55 path_sparc_ifu_dec_75 path_sparc_ifu_dec_93

I think awk/sed can read the file column by column and relocate the strings, but I need help!

I would appreciate any help for this problem.

Best,

Jaeyoung
# 2  
Old 04-26-2016
Perhaps something like:
Code:
awk '
NR > 1 && last != $1 {
	printf("\n")
}
last != $1 {
	printf("%s", $2)
	last = $1
	next
}
{	printf(" %s", $2)
}
END {	printf("\n")
}' file

which with your sample data in a file named file produces the output:
Code:
path_sparc_ifu_dec_104 path_sparc_ifu_dec_105
path_sparc_ifu_dec_63 path_sparc_ifu_dec_92
path_sparc_ifu_dec_39
path_sparc_ifu_dec_43 path_sparc_ifu_dec_71
path_sparc_ifu_dec_103
path_sparc_ifu_dec_99
path_sparc_ifu_dec_55 path_sparc_ifu_dec_75 path_sparc_ifu_dec_93

which doesn't have any trailing spaces (unlike your sample output which sometimes has trailing spaces and sometimes does not have trailing spaces) and which has a single space between output fields (unlike your sample output which has varying numbers of spaces between output fields).

As always, if you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk.
# 3  
Old 04-26-2016
try also:
Code:
echo "" | cat infile - | awk '{printf (NR == 1 ? $NF : ((! a[$1]) ? "\n" : " ") $NF) ;  a[$1]++ }'

# 4  
Old 04-27-2016
If the input is NOT sorted by index values, try
Code:
awk '{T[$1] = T[$1] $2 " "; if ($1 > MX) MX = $1} END {for (i=1; i<=MX; i++) print T[i]}' file
path_sparc_ifu_dec_104 path_sparc_ifu_dec_105 
path_sparc_ifu_dec_63 path_sparc_ifu_dec_92 
path_sparc_ifu_dec_39 
path_sparc_ifu_dec_43 path_sparc_ifu_dec_71 
path_sparc_ifu_dec_103 
path_sparc_ifu_dec_99 
path_sparc_ifu_dec_55 path_sparc_ifu_dec_75 path_sparc_ifu_dec_93

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Relocation strings using awk/sed from a index file

Hi All, I'd always appreciate all helps from this website. I would like to relocate strings based on the index number from an index file. Index numbers are shown on the first column in the index file (index.txt) and I would like to relocate "path" based on index numbers. Paths are placed... (11 Replies)
Discussion started by: jypark22
11 Replies

2. Shell Programming and Scripting

Need to execute Oracle relocation command in shell script

Hello, I need to execute below command in shell script srvctl relocate service -d $database -s $service -i $avail -t $pref -f and also need to get the errors ,if any,in another file. What's the right way to execute such commands in shell script? Best regards, Vishal (1 Reply)
Discussion started by: Vishal_dba
1 Replies

3. Web Development

Svn repository relocation

Hi, I have a svn setup with multiple code repositories. Recently the filesystem holds the repository got full and i wanted to have to move some code repositories to another filesystem. I copied some of the code repositored using the "mv" command to another filesystem and created a symlink with... (1 Reply)
Discussion started by: arumon
1 Replies

4. Linux

relocation truncated to fit

Hi, I am getting linking error i.e. /ade/aime_urtk/oracle/has/include/caa_ResStateListener.hxx:79: relocation truncated to fit: R_PPC_GO T16 vtable for CAA::ResourceStateListener /ade/aime_urtk/oracle/has/lib//libcaad.a(caa_Main.o)(.text+0x88e6): In function `CAA::ResourceStateL... (0 Replies)
Discussion started by: jgobbur
0 Replies

5. Solaris

fatal: relocation error: R_SPARC_WDISP22

Hello, I wonder if anyone has a clue what could be wrong. I get the following error on SUN Netra-T4 server when some applications try to start (e.g. slpd) also even if I try commands such as "jar" I get the same error: ld.so.1: /usr/java1.2/jre/bin/sparc/native_threads/java: fatal:... (3 Replies)
Discussion started by: Juha
3 Replies

6. UNIX for Advanced & Expert Users

relocation error: yyparse referenced symbol not found

This is my set up: LD_LIBRARY_PATH=/apps/rogue_wave_sol7/workspaces/workshop6_u1/4d/lib:/apps/fu/section20/vendorLib/EMS/4.2/lib:/home/a487891/cppunit/lib:/usr/openwin/lib:/usr/lib ldd -d TestDatalinkTradeRouter libintl.so => /usr/lib/libintl.so libw.so.1 => /usr/lib/libw.so.1... (2 Replies)
Discussion started by: agilgeous
2 Replies

7. Programming

ld.so.1: relocation error

Hi Iam getting the following error... ld.so.1: xxxx: fatal: relocation error: file /home/costar4/bin/xxxx: symbol __1cH__rwstdUInterlockedIncrement6Fpl_l_: referenced symbol not found. Can anyone tell me anything in this ? Thanks, Sanja (1 Reply)
Discussion started by: sanjasam
1 Replies

8. Programming

relocation truncated to fit errors

I have 2 directories: a1 and b1 Directory b1 depends on directory a1 Using directory a1, I create a1.lib Using directory b1, I create b1.lib Now, using a1 and b1, I create a shared object ab1.so I've been able to build ab1.so just fine. I made an update to file b1.c and am now getting a... (1 Reply)
Discussion started by: houdini_1
1 Replies

9. UNIX for Advanced & Expert Users

relocation error

when running make command i'm getting the following error: make:relocation error:make:symbol_sprintf_chk,version GLIBC_2.3.4 not defined in file libc.so.6 with link time reference... plz tell me what to do abt this... (1 Reply)
Discussion started by: abhi1826
1 Replies
Login or Register to Ask a Question