[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 813
  • Last Modified:

merge, past, and parse text files

i want to merge first row from file1, file2, file3, .. fileM into new_file
then copy this first row from <new_file>
then past it into row1,row2,.. rowN

also how can i call vi within my script to perform some tasks i.e replacing characters,past, delete,... etc
please advise
thank you
0
nilehawk
Asked:
nilehawk
  • 5
  • 3
2 Solutions
 
ozoCommented:
paste  file1 file2 file3 fileM > new_file
0
 
nilehawkAuthor Commented:
thanks ozo,
yes, it is working ok but still want to know how can i call vi in my script to make copy and past from new_file
i need after merging these file to copy this row and past it several times
thanks
0
 
omarfaridCommented:
vi is an interactive editor that needs terminal to be used. So far I did not come across scripts that call vi and pass commands to it.

You may alternatively use ed, ex, or sed.

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
nilehawkAuthor Commented:
thanks omarfarid
how can i use sed for copy and past lines?
0
 
nilehawkAuthor Commented:
thanks omarfarid
how can i use sed for copy and past lines?
0
 
omarfaridCommented:
here a link to sed tutorial

http://www.grymoire.com/Unix/Sed.html#uh-37

what exactly you want to copy?
0
 
nilehawkAuthor Commented:
i want to copy first row in the assembled fie_new and past it at the end of an_other_file 10 successive times
0
 
omarfaridCommented:
you don't need sed for that, try

#!/usr/bin/bash
line=`head -1 assembled fie_new`
c=1
while test $c -le 10
do
    echo $line >> an_other_file
    c=`expr $c + 1`
done

or

#!/usr/bin/bash
line=`head -1 assembled fie_new`
echo $line >> an_other_file
echo $line >> an_other_file
echo $line >> an_other_file
echo $line >> an_other_file
echo $line >> an_other_file
echo $line >> an_other_file
echo $line >> an_other_file
echo $line >> an_other_file
echo $line >> an_other_file
echo $line >> an_other_file
0
 
nilehawkAuthor Commented:
thanks you for your help
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now