Sponsored Content
Top Forums Shell Programming and Scripting replace text in file using variable Post 302488809 by Toug on Tuesday 18th of January 2011 12:55:53 PM
Old 01-18-2011
reply for joeyg:

here is a summary:

Code:
bootsize=$(ls -l *boot.bin | awk '{printf "%10d %s\n",$5,$9}')  #this line return the size of a file named XXXXXboot.bin and put it in the bootsize variable(only one file in the current folder)
let bootsize=bootsize/512                                        #this line return the number of 512 bytes block of bootsize
let bootsize=bootsize+1                    
folderpath=$(pwd)                                                # return the current folder in use in the folderpath variable
bootpath=$(ls -a *boot.bin)                                        # return the name of the XXXXboot.bin
bootpathf=$folderpath/$bootpath                                    # return the full path of the XXXXXboot.bin
cp ../../TEMPLATE_OS_STITCH_penwellB0.xml $rootfspath.xml        # copy a config template file to be modified into the current folder and name it with another file (+ .xml)
sed -i "s/BOOTPATH/$bootpathf/g" $rootfspath.xml                # modify the file to replace the pattern BOOTPATH by the XXXXboot.bin full path

I hope this will help to understand.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find and replace text with a variable?

Is there a way that I can make the following work with using variables? perl -pi -e 's#blah#hrm#ig' replacetext but like this var=blah perl -pi -e 's#$var#hrm#ig' replacetext (3 Replies)
Discussion started by: doublejz
3 Replies

2. Shell Programming and Scripting

Sed , Replace a "variable text" inside of a statement

Please Help... I am trying to manipulte the following line Before : <user:Account_Password>002786</user:Account_Password> the password is the "variable", i need to delete / omit the password in the file, (it occurs several thousand times) so the tag line looks like After:... (4 Replies)
Discussion started by: jackn7
4 Replies

3. UNIX for Dummies Questions & Answers

sed to replace text with a variable

I'm trying to replace text in a file with text from a variable I have the following in my script, but its not working: #!/bin/ksh echo "Enter the path to load scripts" read x echo "updating the templates" sed "s/CHANGE_ME_TO_LOAD_PATH/"$x"/g" LoadFiles.sh > LoadFiles2.sh I thought... (1 Reply)
Discussion started by: orahi001
1 Replies

4. UNIX for Dummies Questions & Answers

search and replace a specific text in text file?

I have a text file with following content (3 lines) filename : output.txt first line:12/12/2008 second line:12/12/2008 third line:Y I would like to know how we can replace 'Y' with 'N' in the 3rd line keeping 1st and 2nd lines same as what it was before. I tried using cat output.txt... (4 Replies)
Discussion started by: santosham
4 Replies

5. Shell Programming and Scripting

How to replace text in a file with text entered

I am trying to write a shell script that will allow the typing of a value, then using that value to replace data in a text file. I suspect I need sed. The format of the file is: Variable1:Value1 Variable2:Value2 The interaction would be something like: Shell Prompt: "Please enter the... (9 Replies)
Discussion started by: cleanden
9 Replies

6. Shell Programming and Scripting

Replace variable names in text file with its value

Hi I have a text file (mytext.txt), the content of which is as following: My name is <@MY_NAME@> and my age is <@MY_AGE@> . Now i have another property file (myprops) which is as following: MY_NAME=abcdefgh MY_AGE=000000 I was wondering, how can i replace the tags of mytext.txt, with its... (1 Reply)
Discussion started by: vigithvg
1 Replies

7. Red Hat

How to pass value of pwd as variable in SED to replace variable in a script file

Hi all, Hereby wish to have your advise for below: Main concept is I intend to get current directory of my script file. This script file will be copied to /etc/init.d. A string in this copy will be replaced with current directory value. Below is original script file: ... (6 Replies)
Discussion started by: cielle
6 Replies

8. Windows & DOS: Issues & Discussions

2 Questions: replace text in txt file, add text to end of txt file

so... Lets assume I have a text file. The text file contains multiple "#" symbols. I want to replace all thos "#"s with a STRING using DOS/Batch I want to add a certain TEXT to the end of each line. How can I do this WITHOUT aid of sed, grep or anything linux related ? (1 Reply)
Discussion started by: pasc
1 Replies

9. UNIX for Dummies Questions & Answers

Replace variable string with text

Hi All, Hoping someone can help.... I am trying to work out how I can ammend a log file to remove variable strings in order to remove confidential information which I cant pass on. As an example I have used phone numbers. A large log file contains multiple lines containing something like the... (6 Replies)
Discussion started by: mutley2202
6 Replies

10. UNIX for Beginners Questions & Answers

How to replace a parameter(variable) date value inside a text files daily with current date?

Hello All, we what we call a parameter file (.txt) where my application read dynamic values when the job is triggered, one of such values are below: abc.txt ------------------ line1 line2 line3 $$EDWS_DATE_INSERT=08-27-2019 line4 $$EDWS_PREV_DATE_INSERT=08-26-2019 I am trying to... (1 Reply)
Discussion started by: pradeepp
1 Replies
FTL_FORMAT(1)						      General Commands Manual						     FTL_FORMAT(1)

NAME
ftl_format - Flash Translation Layer formatting utility SYNOPSIS
ftl_format [-q] [-i] [-s spare] [-r reserve] [-b bootsize] device DESCRIPTION
Ftl_format creates a Flash Translation Layer partition on a flash memory device. It needs to access the flash partition's raw character- mode device (such as /dev/mem0c0c). This is actually a low-level format operation, required before accessing a memory device via the FTL block device driver. Once a partition is prepared with ftl_format, a filesystem should be created in a separate step. Filesystem commands should access the device via the FTL device file (such as /dev/ftl0). Optionally, ftl_format can reserve a region at the beginning of the flash card address space for a boot image (or any other purpose). The boot area is not part of the FTL partition, and can only be accessed via the raw memory device. On Intel Series 100 flash cards, the first flash block is used to store the card's configuration information structures. If no boot area is specified on the command line, ftl_format will automatically create one to span the first block. OPTIONS
-q Quiet mode: don't print formatting statistics. -i Interactive: confirm before beginning the format. -s spare Reserve the specified number of erase blocks as spares. The default is 1. A read-write partition requires at least one spare block. -r reserve Reserve the specified percentage of the total space on the device to improve write efficiency. The default is 5%. Reserving less space increases the frequency of flash erase operations to reclaim free blocks. -b bootsize Requests that a portion of the flash card be reserved for a boot image. The size will be rounded up to an integral number of erase blocks. AUTHOR
David Hinds - dahinds@users.sourceforge.net SEE ALSO
ftl_cs(4), ftl_check(8). pcmcia-cs 2000/06/12 21:24:48 FTL_FORMAT(1)
All times are GMT -4. The time now is 03:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy