formatting and merging 2 data files

Hi,
I have 2 files that I got as an output from another program. They are :

File 1

((((((CtBJa:197.0,CtBTz:197.0):85.0,CtAHr:197.0):116.0,CtDUw:197.0):176.0,CtSwe:197.0):110.0,
(CtL2b:197.0,Ct4Bu:197.0):196.0):197.0,CmuNg:197.0);
((((CtL2b:200.0,Ct4Bu:200.0):177.0,((CtAHr:200.0,CtBJa:200.0):77.0,(CtBTz:200.0,
CtDUw:200.0):84.0):127.0):130.0,CtSwe:200.0):200.0,CmuNg:200.0);
(((CtBJa:200.0,CtAHr:200.0):102.0,(((Ct4Bu:200.0,(CtBTz:200.0,CtSwe:200.0):147.0):115.0,
CtDUw:200.0):73.0,CtL2b:200.0):105.0):200.0,CmuNg:200.0);
((((((CtBTz:200.0,CtAHr:200.0):70.0,CtDUw:200.0):68.0,CtBJa:200.0):172.0,(Ct4Bu:200.0,
CtL2b:200.0):178.0):135.0,CtSwe:200.0):200.0,CmuNg:200.0);
((CtSwe:200.0,(((((CtAHr:200.0,CtBJa:200.0):92.0,CtDUw:200.0):48.0,CtBTz:200.0):126.0,
Ct4Bu:200.0):81.0,CtL2b:200.0):135.0):200.0,CmuNg:200.0);
(((((CtL2b:200.0,Ct4Bu:200.0):125.0,((CtAHr:200.0,CtSwe:200.0):85.0,CtBTz:200.0):92.0):107.0,
CtDUw:200.0):173.0,CtBJa:200.0):200.0,CmuNg:200.0);
((CtSwe:200.0,(((((CtBTz:200.0,Ct4Bu:200.0):106.0,CtDUw:200.0):79.0,CtL2b:200.0):68.0,
CtAHr:200.0):78.0,CtBJa:200.0):128.0):200.0,CmuNg:200.0);
((((((Ct4Bu:200.0,(CtBTz:200.0,CtSwe:200.0):113.0):85.0,CtL2b:200.0):75.0,CtAHr:200.0):92.0,
CtBJa:200.0):140.0,CtDUw:200.0):200.0,CmuNg:200.0);

File2

10
100
101
102
103
104
105
106
107
108

For File 1 what i need is; each line should be separated by a ';'. But the file I have (file 1), it is split into 2 lines. What I want is, make them one line so that every line ends with ';'. Its like make every 2 lines in the current format to one line and each have the ';' at the end position.

Once I have file 1 in the right format, I need to merge file 2 with file 1 in the same order separated by a tab. Like this:

1st line of file 2 tab 1st newly format line of file 1
2st line of file 2 tab 2st newly format line of file 1
3st line of file 2 tab 3st newly format line of file 1
4st line of file 2 tab 4st newly format line of file 1
5st line of file 2 tab 5st newly format line of file 1
6st line of file 2 tab 6st newly format line of file 1

Please let me know the best way to do this formating using unix or awk.

LA

---------- Post updated at 06:29 PM ---------- Previous update was at 06:25 PM ----------

Like wise I have 1000's of lines in each file

LA

sed '$!N;s/\n//' file1 |sed 's/;//' > tmpfile
paste tmpfile file2

Try:

paste  <(awk '!/;/ {_s=$0;} /;/ { print _s,$0; }' file) <(cat file2)

Just awk :wink:

awk '{getline _<x;printf "%s\t%s",_,$0;getline;print}' x=file2 file1

Hi you can use the following Script ......

Script:

for file in `cat filelist`
do
 rm -r ${file}-arr 1>/dev/null 2>/dev/null
    count=1
    while read line
    do
      if [ $(($count % 2)) -eq 0 ]
      then
      echo "echo $line" >>$file-arr
      else
      echo "$line\c" >>$file-arr
      fi
     ((count=$count+1))
    done < $file
done
paste file2 ${file}-arr >$file-final

Files used here:

file2 ---- second file (while you mentioned as file2 in the post)
$file-arr ---intermediate generated file after rearrangement of lines in file1
$file-final ---- final required output file
filelist ---- a file contains a list file1 types

Hope this will help you or else atleast it will give you some idea to proceed further.

Hi All,

I have the same file format as shown in file 1 but this time it is not in 2 lines i.e the ";" doesn't come every 2 lines.

How would i modify the above sed/awk code in such way that

For File 1 what i need is; each line should be separated by a ';'. But the file I have (file 1), it is split into 2 or more lines (not fixed all are above 10 lines now. What I want is, make them one line so that every line ends with ';'. Its like make every lines in the current format to one line and each have the ';' at the end position.
Let me know