awk command issue

Hi All,

I have one file with below content

 
 Post1:uri
Post2:urieop
Post3:urtei

I am trying to read each word seprated by delimiter with below command

 
Value1=$(awk -F":" '{print $1}' $HSFILE)
Value2=$(awk -F":" '{print $2}' $HSFILE)
echo $Value1
echo $Value2

It is giving output to me

 
Post1
Post2
Post3
 
uri
urieop
urtei

But I want in

 
Post1
uri
Post2
urieop
Post3
urtei

Could you please suggest?

Try:

awk '1' RS=':'  infile

I believe below will get you what you're looking for.

d@AirBox:~$ v1=($(awk -F\: '{print $1}' file))
d@AirBox:~$ v2=($(awk -F\: '{print $2}' file))
d@AirBox:~$ for ((i=0 ; i < ${#v1[@]} ; i++));do printf "${v1[$i]}\n${v2[$i]}\n";done
Post1
uri
Post2
urieop
Post3
urtei

In shell, because insomnia.

d@AirBox:~$ while read line;do  printf "${line%%:*}\n${line##*:}\n";done < file
Post1
uri
Post2
urieop
Post3
urtei
d@AirBox:~$
1 Like
$ tr ':' '\n' < file
Post1
uri
Post2
urieop
Post3
urtei
1 Like

Hello,

Could you please try the following code please.
Let us say test_file have the data as per your request.

$ cat test_file.ksh
value1=`awk -F: '{print$2}' test_file`
value2=`awk -F: '{print$1}' test_file`
k=0
l=0
set -A array_value1 ${value1}
set -A array_value2 ${value2}
for i in ${array_value1[@]}
do
l=0
for j in ${array_value2[@]}
do
if [[ $k -eq $l ]]
then
echo $j
echo $i
fi
let "l = l +1 "
done
let "k =k +1 "
done

Then Output should be as follows.

$ ksh test_file.ksh
Post1
uri
Post2
urieop
Post3
urtei

Thanks,
R. Singh

1 Like

thanks Guys, Evryone's code is working

I am going to use DeCoTwc code.