Combining data from file

Hi All,

I have file f1 contains :

f1;

Server Name1
te-1212hdsfhf-12kll-56565
Server Name2
jd-1212hdsfhf-12kll-5677
Server Name3
ty-1212hdsfhf-12kll-444
....

I have to produce f2 with the output:

f2:

Server1 te-1212hdsfhf-12kll-56565
Server2 jd-1212hdsfhf-12kll-5677
Server3 ty-1212hdsfhf-12kll-444

Can we write one liner for this ?

Thanks
'Krsna!

$ nawk '{a=$1;a=a""substr($2,length($2)-1,length($1));getline;printf("%s %s\n",a,$0)}' input.txt
Servere1 te-1212hdsfhf-12kll-56565
Servere2 jd-1212hdsfhf-12kll-5677
Servere3 ty-1212hdsfhf-12kll-444
awk 'NR%2{gsub(/[A-Za-z]/,z,$2);$1=$1 $2;printf $1 FS;next}1' file
awk '{$1="Server" (++i);getline $2}1' infile
awk '{$1=$1 (++i);getline $2}1' infile

Thanks All,

Hi Scurit,

Your code is giving output like :

Server te-1212hdsfhf-12kll-56565
Server jd-1212hdsfhf-12kll-5677
Server ty-1212hdsfhf-12kll-444

Server 1,2,3 is missing. Server name can be anything?

Thanks
Krsna

use awk, if you dont have nawk

Hi Itkamaraj,

Thanks , If you do not mind can you please explain me this one liner how diff parts works..

nawk '{a=$1;a=a""substr($2,length($2)-1,length($1));getline;printf("%s %s\n",a,$0)}' input.txt

Thanks
Krsna

On Solaris use /usr/xpg4/bin/awk rather than awk

a=$1 --> a will hold the first field
a=a""substr($2,length($2)-1,length($1)) --> append the last character of second filed with a
getline --> read the next line ( so that $0 will be having the next line )

1 Like

Hi itkamaraj ,

Got it many thanks

Thanks to all.

cat FILE | paste - - | sed 's/ Name//'
1 Like

Thanks Yazu,

cat FILE | paste - - | awk '{ print $1$2 "\t" $3}' giving me right output.

Thanks again for easy sol.