Moving a part of the text in a file

***************
#some other text

*****************
[unicast]

***************
#some other text

*****************
address1=1.1.1.1
address2=2.2.2.2
address3=3.3.3.3

I have a file where i need to push all the text starting from address1 till end of file to, below [unicast]. Can anyone of you help?? Thanks for the solution. I tried getting the line number of the [unicast]. But it was of no use. Also i need to delete it after i move the text.

Hi
You can use this sample of code:

 
APP_CONF=./myfile.txt
NEW_FILE=./NewFile.txt
WANTED_STRING="address"
awk -F";" '{print $1}' $APP_CONF | while read RAW
 do
  if [[ $RAW == $WANTED_STRING* ]] then
   echo $RAW>> $NEW_FILE
  fi
 done

or simply, you can use this command:

 grep "address" ./myfile.txt > newFile.txt

Cheers

Thank you very much :slight_smile: for the immediate response.

I wanted a script command and also after putting address1 and following text below [unicast] i need to delete it.

grep "address" ./myfile.txt > newFile.txt
cat myfile.txt | grep -v address > myfile1.txt
mv myfile1.txt myfile.txt

put these three lines in a file and run it, probably it will work.

it did not work :frowning:

What is your expected o/p from the i/p file you have given above?

cheers,
Devaraj Takhellambam

wats the issue?? any error??