0

hi all

i want to take a paragraph from a file and append this paragraph after ^L in another fille using shell scripting .............could you help me

2
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by issue9
0

Hello reham84,

assuming paragraphs are separated by blank empty lines
you might want to try this one:

awk 'BEGIN{ RS="" } { if(NR == 3){ printf("^L%s", $0) } }' fromfile >> anotherfile

It should print a formfeed and the third paragraph from "fromfile" at the end of "anotherfile".

Regards,
issue9

0

thank you issue9 but i have mad the folowing

sed -n '3,6p' 123.0912210926>11.tmp
x=`cat ismail.tmp`

11.tmp will contain the paragraph i need to append on the other file
then i have put this paragraph value in x

now i want to append this paragraph in another file after a certain text through this file using ksh

Edited by Nick Evan: n/a

0

sed -n '3,6p' 123.0912210926>11.tmp
x=`cat 11.tmp`

11.tmp will contain the paragraph then i put this paragraph value in variable x

now i want to append this paragraph in another file after a certain text through this file using ksh

0

Hello reham84,

now that you have got the paragraph in "11.tmp"
you can search for "certain text" in "anotherfile"
and print it after the line where you found it:

Please try

awk '{
   print
   # print every line of the file anotherfile
}
/certain text/{
   while(getline < "11.tmp") { print }
   # if certain text is found print all lines of 11.tmp
}' anotherfile > anotherfile.tmp
mv anotherfile.tmp anotherfile

Sorry, the stuff above is not tested,
just wrote it down, should work though...

Hopefully it helps.

Regards,
issue9

0

lots of thank issue9

it works but i have a little problem i want to append this paragraph after every pattern matches the text as this text is repeated through the file
this script it append only after the first pattern it matches

0

well, yes, reham84,

my last post assumed that "certain text" occurs only once in a single line.

Perhaps a different approach could fit:

sed -n '3,6p' 123.0912210926>11.tmp
x=`cat 11.tmp`
CERTAINTEXT="certain text"
sed 's/\('${CERTAINTEXT}'\)/\1^L'"${x}"'/g' anotherfile > anotherfile.tmp
mv anotherfile.tmp anotherfile

Regards,
issue9

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.