LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-25-2015, 08:53 AM   #1
Aashika
LQ Newbie
 
Registered: Sep 2014
Posts: 15

Rep: Reputation: Disabled
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??
 
Old 06-25-2015, 11:24 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,251

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
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.
 
1 members found this post helpful.
Old 06-29-2015, 08:21 AM   #3
Aashika
LQ Newbie
 
Registered: Sep 2014
Posts: 15

Original Poster
Rep: Reputation: Disabled
That helped me.. Thanks a lot..
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] awk: cmd. line:1: fatal: cannot open file `{print' for reading (No such file or direc linuxandtsm Programming 9 10-28-2013 10:13 AM
read a line from file , parse it and store in variables,print them using shell script swapnika.a60 Linux - Newbie 2 12-20-2012 08:20 AM
read line by line a text file and define a file from each file yasmine Linux - Newbie 5 12-10-2012 05:53 AM
How can I read a file line by line and add it to a loop in another file? astroumut Linux - Newbie 7 08-24-2009 05:37 AM
linux scripting help needed read from file line by line exc commands each line read atokad Programming 4 12-26-2003 11:24 PM


All times are GMT -5. The time now is 09:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration