replacing text with contents from another file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting replacing text with contents from another file
# 1  
Old 02-05-2009
replacing text with contents from another file

I'm trying to change the ramfs size in kernel .config automatically.

I have a ramfs_size file generated with du -s
cat ramfs_size
64512

I want to replace the linux .config's ramdisk size with the above value
CONFIG_BLK_DEV_RAM_SIZE=73728

Right now I'm doing something dumb like:
size=`cat ramfs_size`
linux_size=`awk -F'=' '/DEV_RAM_SIZE/ {print $2}' .config
sed -i 's/$linux_size/$size/g' .config

It's not working from Makefiles because I think it gets confused with the $ dereference... Is there a simpler awk/sed line I can do?
# 2  
Old 02-05-2009
may not be dumb so much as uncuddled...unless there's a reverse typo it looks like you'd be able to achieve it once you properly wrap the inline function:

You'd posted:

Code:
size=`cat ramfs_size`
linux_size=`awk -F'=' '/DEV_RAM_SIZE/ {print $2}' .config
sed -i 's/$linux_size/$size/g' .config

Did you mean to say:

Code:
size=`cat ramfs_size`
linux_size=`awk -F'=' '/DEV_RAM_SIZE/ {print $2}' .config `
sed -i 's/$linux_size/$size/g' .config

Better yet:

Code:
size=$(cat ramfs_size)
linux_size=$(awk -F'=' '/DEV_RAM_SIZE/ {print $2}' .config )
sed -i 's/$linux_size/$size/g' .config

Whatever works, works, but backticks are too easily mistaken for nonsense...or left out...
# 3  
Old 02-05-2009
Yes that's what I mean. Problem is I can't seem to invoke these lines in my Makefile. I think it gets confused with the $2 environment variable dereference.
# 4  
Old 02-05-2009
did you re-check your makefile for the backticks? or try the alternate in-line formatting? back-ticks were deprecated for this very reason...although there may be others...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Echo variable contents into a text file...

Hi all, I am trying to create a script to read my Windows UUIDs and create mounts in fstab. I know there are different and maybe even better ways to mount Windows partitions at boot time, but I always manually create them in fstab successfully. I do a clean install of Ubuntu often and would like to... (2 Replies)
Discussion started by: Ian Pride
2 Replies

2. UNIX for Dummies Questions & Answers

Replacing a particular string in all files in folder and file contents

I need to replace all filesnames in a folder as well as its content from AK6 to AK11. Eg Folder has files AK6-Create.xml, AK6-system.py etc.. the files names as well as contents should be changes to AK9-Create.xml, AK9-system.py etc All files are xml and python scripts. ---------- Post... (0 Replies)
Discussion started by: Candid247
0 Replies

3. Shell Programming and Scripting

sed command for copying the contents of other file replacing it another file on specifc pattern

We have 2 file XML files - FILE1.XML and FILE2.xml - we need copy the contents of FILE1.XML and replace in FILE2.xml pattern "<assignedAttributeList></assignedAttributeList>" FILE1.XML 1. <itemList> 2. <item type="Manufactured"> 3. <resourceCode>431048</resourceCode> 4. ... (0 Replies)
Discussion started by: balrajg
0 Replies

4. UNIX for Dummies Questions & Answers

Replacing a column in a text file

Say I had a text file that contained four columns, like the following: Mack Christopher:237 Avondale Blvd:970-791-6419:S Ben Macdonor:30 Dragon Rd:647-288-6395:B I'm making a loop that will replace the fourth column a line in the file with the contents of a variable 'access', but I have no... (6 Replies)
Discussion started by: Sotau
6 Replies

5. Shell Programming and Scripting

Replacing string in all instances (both filenames and file contents) in a directory

Hi, I have a set of files stored in a single directory that I use to set parameters for a physics code, and I would like to streamline the process of updating them all when I change a parameter. For instance, if the files are called A2000p300ini, A2000p300sub, A2000p300run, and the text in each... (3 Replies)
Discussion started by: BlueChris
3 Replies

6. Shell Programming and Scripting

replacing text in a file, but...

Hi all, Very first post on this forums, hope you can help me with this scripting task. I have a big text file with over 3000 lines, some of those lines contain some text that I need to replace, lets say for simplicity the text to be replaced in those lines is "aaa" and I need it to replace it... (2 Replies)
Discussion started by: Angelseph
2 Replies

7. Shell Programming and Scripting

Replacing contents in a file from multiple programmes

Hi All, I have a query on Perl. I have a text file which has 3 lines, i want to only replace the first line with my replaced text and keep the rest of the text. FOr eg Before change --> echo:a:pending echo:b:pending echo:c:pending After change ---> echo:a:done echo:b:pending... (1 Reply)
Discussion started by: tosatesh
1 Replies

8. Shell Programming and Scripting

Replacing Text in Text file

Hi Guys, I am needing some help writing a shell script to replace the following in a text file /opt/was/apps/was61 with some other path eg /usr/blan/blah/blah. I know that i can do it using sed or perl but just having difficulty writing the escape characters for it All Help... (3 Replies)
Discussion started by: cgilchrist
3 Replies

9. Shell Programming and Scripting

Need help in parsing text file contents

Hi, I need some help in extracting the Exception block between the lines 21 Feb 01:18:54:146 ERROR com.orbits.frameworks.integrationframework.ValidationException - Caught exception in validateRequest() (PID=565584) and 21 Feb 01:18:55:149 INFO ... (0 Replies)
Discussion started by: Alecs
0 Replies

10. Shell Programming and Scripting

replacing strings with text from other file

Hi, Im trying to update some properties files with text from another file: file1 user=xyz file2 user= after script file2 user=xyz Im using this reading the $QUARTZURL,ETC... from quartz.properties: echo... (1 Reply)
Discussion started by: mc1392
1 Replies
Login or Register to Ask a Question

Featured Tech Videos