Saturday 4 May 2013

Merging lines in two files

merge 1st line file1  2nd line as 1st line of 2nd file 

#! /bin/sh
echo "enter the first file name"
read first_file
echo "enter the second file name"
read second_file
echo "$first_file  $second_file"
echo "enter output file name"
read out_file

merge(){
paste -d"\n" $first_file $second_file|sed -e '/^$/d'>$out_file
}

merge;


I/P:

cat file1
aaa
bbb
ccc
bash-4.2$ cat file2
a
b
c
d
e

execution:

bash-4.2$ merge.sh
enter the first file name
file1
enter the second file name
file2
file1  file2
enter output file name
out

O/P:

bash-4.2$ cat out
aaa
a
bbb
b
ccc
c
d
e


0 blogger-disqus:

Post a Comment