Bash Scripting Help to automate replacing multiple lines
Background:
I am writing a script to help me automate tweaks and things I apply to a custom Android rom I developed. I am on the very last part of my script, and I am stuck trying to find the right command to do what I seek.
When I build roms from source, a file called updater-script is generated and it always has the signature of the source code's creator. Since I am now building it from source, I have to replace this signature with my own. Also there are a few commands I add in to make some apps uninstallable.
What I am looking for:
I want to automate the text replacement. I have created two files, one is called findsts and the other replaceccore.
findsts contains the signature that is ALWAYS in the updater-script. I want to use this file to tell the command I am to use that that is the selection I want replaced.
replaceccore has my signature and will eventually have commands to replace text in the updater-script, but for now I just want the signature replaced with the data in this file.
I first thought sed was the answer, but soon found that sed doesn't like variables, but rather would use literal strings. I was then referred to awk. Awk seems to be a very powerful command, but I have yet to see how it will help me in my current situation. I also know that the signature that i am finding and replacing has tons of special characters, including parenthesis, semi colons, and quotations. This also poses a problem because now not only do I need to figure out the correct command, but then how to tell it to use these files in a literal way and not try to interpret the commands in the file.
The details:
findsts contains:
replaceccore contains:
Here is a small part of updater-script, the file I actually am trying to edit, from the beginning of the file:
If it makes a difference I know the developers who provide the source code and they are okay with other developers building roms from source and customizing it.
Thank you for reading. I hope this is not too complicated a task or annoying. I have been searching for a few days and finally broke down and decided to ask. Please be merciful
Edit:
So if sed actually worked this way, I would set it up like this:
but it doesn't, so here I am, back at the drawing board.
Last edited by joeyg; 12-18-2012 at 04:25 PM..
Reason: more detail
What comes to mind is to delete these ui_print lines, and then copy in some new ui_lines.
However, without seeing more of the code, hard to say. For instance, are these ui_print lines always only eleven lines, and occurring at the same point?
In updater-script, the 11 line STS Team signature always is present on the 8th line, unless the rom base does not use the backup tool. In that case, the STS Team signature would start on line 2, after the show progress command.
sed s command works on strings, not input files!
Further, the strings are regular expressions - not wanted here.
But there are other Unix tools:
If you don't want the intermediate patchfile:
This looks promising. I know now that sed likes literal strings and not input files . I love learning code and am excited that there is a community here willing to share their knowledge when I have problems finding it on my own.
@Joeyg, I like your approach as well, this helps me to understand some more commands. Does the head and tail commands used in this context copy the selected lines to files t1 and t2, and then im a little lost what the cat command does to mytext.txt and newfile.txt, assuming that new.txt has the information in my replaceccore file.
---------- Post updated at 06:45 PM ---------- Previous update was at 06:32 PM ----------
This worked like a charm!
---------- Post updated at 06:55 PM ---------- Previous update was at 06:45 PM ----------
Im looking for a bash solution that will use Regular Expressions (not perl, sed or awk) to check the example data below and then give me a status.
which would be just simply Match or Mismatch.
SYS PS1 is present.
Fan status: Normal
Input Voltage status: Normal
... (5 Replies)
Hi
I am new to Ubuntu and Bash scripting. I am working on a project to give a demo on an SDN application to my class. I need some help in scripting to create the demo. Please help in case if you have any idea on what am asking.
The demo uses a tool called mininet. I need just one script so... (2 Replies)
Hi
Am confused with the usage of "sed" command
I want to replace a single line with multiple lines of a file..
eg.,
A file has
Hi, How are you?
I need to replace as
Am fine
What are You doing?
I used the script as
string1="Hi, How are you?"
echo "$string1 is the value"... (4 Replies)
Hi,
Can anyone help me out for my below problem.
I need to replace all System.out.println with Logger.println in *.java using SED (spanning multiple lines)
including current & sub-directories.
I tried with below command. But it is not replacing when source text is spanned over multiple... (4 Replies)
Hi,
I have a file with below contents,
ssenthil = rw
anilkg = rw
I want to search for "ssenthil" and need to delete line 1 and 2 , if the third line starts with "" respectively and blank line immediately and third line starts with "
anilkg = rw
Please help me .
Great day... (5 Replies)
Hi there, I have the following output,
# raidctl -l
RAID Volume RAID RAID Disk
Volume Type Status Disk Status
------------------------------------------------------
c0t1d0 IM OK c0t1d0 OK
... (4 Replies)
Hey guys,
I'm kinda a noob at scripting. I am trying to create a script that uses multiple for loops with the lsiutility to monitor disk health on a system.
The script runs, but it will continually echo an infinite number of LogVolumes when there are only 2 per virtual disk on my server. It's... (2 Replies)
Can any one give me the idea on replacing multiple blank lines with a single blank line?
Please conside it for a file having more than 100 number of characters.
Regards,
Siba (3 Replies)