LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to read one file and print its value in another file on a particular line (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-read-one-file-and-print-its-value-in-another-file-on-a-particular-line-4175546405/)

Aashika 06-25-2015 07:53 AM

how to read one file and print its value in another file on a particular line
 
I have a file from which I have to read the value from the first line and store it in another file on a particular line number in the format
Code:

var="value"
I tried the following sed command and it copies the value from source-file in the destination-file on line 7..
Code:

sed $'7{e sed "1!d" /source-file.txt\n}' -i /destination-file.txt
The above command just prints out the exact value as it was in the source-file, how do I modify the command to write it in the var="value" format in the destination file??

grail 06-25-2015 10:24 AM

Personally I would just use the read command to get the first line of the file into a variable and then use sed's insert option (see here)
to write the appropriate line to the file.

Aashika 06-29-2015 07:21 AM

That helped me.. Thanks a lot.. :) :)


All times are GMT -5. The time now is 11:29 PM.