Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Using sed to change lines and add them if they don't exist.. Post 302638927 by Silentbtdeadly on Friday 11th of May 2012 09:01:03 AM
Old 05-11-2012
Using sed to change lines and add them if they don't exist..

I've googled the hell out of this, and in my quest to advance my knowledge and expertise in modifying phones to make them more awesome, I ended up here.
I've found answers about patterns and whatnot that seem really complex for what I am trying to do, and basically it is this:
if the line says
Code:
ro.ril.gprsclass=10

I want to change it to
Code:
ro.ril.gprsclass=12

- if I understand right then that would be easy -
Code:
sed 's/^ro.ril.gprsclass=*/ro.ril.gprsclass=12/g' /system/build.prop

(the file I am modifying)
But what would be the easiest way to add that line IF there was no line that contained "ro.ril.gprsclass="?
I know this may be a dumb question, but I am looking for the SIMPLEST way of doing this(there will be many lines modified like this, and I want to keep it simple to avoid possible errors)?
I am only trying to modify/add the lines that start with RO(read-only), I can create another file that will supercede any files that don't start with that..
In case it helps, what I have so far is:
Code:
#!/sbin/sh
busybox echo "" >> /system/build.prop
busybox echo "# xLoud" >> /system/build.prop
busybox echo "ro.semc.sound_effects_enabled=true" >> /system/build.prop
busybox echo "ro.semc.xloud.supported=true" >> /system/build.prop
busybox echo "persist.service.xloud.enable=1" >> /system/build.prop
busybox echo "com.sonyericsson.xloud_enabled=true" >> /system/build.prop
busybox echo "xloud_enabled=true" >> /system/build.prop
busybox echo "ro.semc.xloud.default_setting=true" >> /system/build.prop
sed 's/^ro.product.version=*/ro.product.version=Revolutionized Nonsense 2.1Final/g' /system/build.prop
busybox echo "" >> /system/build.prop

The last line will replace a line I KNOW is there, but I need this answer to make sure that I don't create multiple entries of the same code(and the first entry takes precedence anyways)
If anything here is unclear let me know, but for me I am clearly going from developing for a phone to coding- and all the instructions I have found thus far are complex or just plain confusing..

---------- Post updated at 09:01 AM ---------- Previous update was at 12:22 AM ----------

Someone in the phone forums said I could use grep + sed to get it done, they didn't give me a solid example, but I'm guessing it would look something like this?
Code:
if grep ro.ril.gprsclass= /system/build.prop ; then 
sed -d 's/^ro.ril.gprsclass=*/ro.ril.gprsclass=12/g' /system/build.prop 
else 
busybox echo "ro.ril.gprsclass=12" >> /system/build.prop

I'm unsure about the formatting, but if the above worked and there WAS a line that said "ro.ril.gprsclass=8" it would change it to 12, or if there was no line it would add it to the end of the original file.. am I correct?
I'd appreciate any feedback, it seems much easier to find complex ways of doing these things that may work, much harder to find the simplest way that WILL work..
Thanks in advance!

SBD

Last edited by Silentbtdeadly; 05-11-2012 at 11:33 AM.. Reason: Code tags were being used, but added some extra code tags
 

9 More Discussions You Might Find Interesting

1. Solaris

Change password - User does not exist

When trying to change the password with the command "passwd" it returns that the user does not exist. passwd <USER> passwd: changing password for <USER> passwd: <USER> does not exist This is a Solaris 2.5.1 system. (7 Replies)
Discussion started by: ryamada
7 Replies

2. Shell Programming and Scripting

Sed Add New Lines

Hello, I have a file that has data like this: one two three four five six seven eight nine ten Is there a quick way using sed of nawk to put each word on it's own line? Thanks. (2 Replies)
Discussion started by: bestbuyernc
2 Replies

3. Shell Programming and Scripting

Sed insert and Change lines help needed

Hi, How can i use insert and change command in ksh shell. I am using : sed -e '1i\TEXTTOBEINSERTED\' FILENAME But there is no effect... Also sed -e 'c\thisischange\' Filename Please Explain how to proceed?? (2 Replies)
Discussion started by: JunkYardWars
2 Replies

4. Shell Programming and Scripting

Add lines with sed or awk

I want to get an output from the input as below: Input: ASDDS14 RXOTX-39-8 AB0991C TRY1900 AEDFS12 RXOTX-39-9 TK0991C TRY800 HSVDS11 RXOTX-389-10 LG0991C TRY1900 BSDDS09 RXOTX-394-0 AA0066A TRY800 OUTPUT: ASDDS14 RXOTS-39-8-0 AB0991C TRY1900... (2 Replies)
Discussion started by: aydj
2 Replies

5. Shell Programming and Scripting

How to use sed command for change special lines?

Hi, I want to add a character "#" in this few lines with sed command Initial: ### CACCIA: DEBUT ### if $(grep -wqi "$2" /etc/passwd); then chuser -R files registry=files $2 fi ### CACCIA: FIN ### Result with sed command: ### CACCIA: DEBUT ### #if $(grep -wqi "$2"... (4 Replies)
Discussion started by: khalidou13
4 Replies

6. Shell Programming and Scripting

Remove words from file2 that don't exist in file1

Hi I have to list of words file1 and file2, I want to compare both lists and remove from file2 all the words that don't exist in file1. How can I do this? Many thanks (4 Replies)
Discussion started by: noliveira
4 Replies

7. UNIX for Dummies Questions & Answers

Change unix permission when I don't own the file

Hi, A file is transferred from a Windows server(say username : user1) to Unix server via ftp. In unix, the permission of the file for a user, say user2 will be "-rw-r-----". Since the user1 is the owner of the file, user2 is not able to change the file permission using chmod. Is there... (5 Replies)
Discussion started by: merin
5 Replies

8. Shell Programming and Scripting

Add character to specific columns using sed or awk and make it a permanent change

Hi, I am writing a shell script where I want that # should be added in all those lines as the first character where the pattern matches. file has lot of functions defined a.sh #!/bin/bash fn a { beautiful evening sunny day } fn b { } fn c { hello world .its a beautiful day ... (12 Replies)
Discussion started by: ashima jain
12 Replies

9. Shell Programming and Scripting

Add string into certain lines - sed

Hello all, I have surely an easy question - but at the moment I do not see the solution. All what I want is to add the string "/9201" within a file when a line starts with ":47A:". This is how a file look like: Information Tool :12:Delimiter :3:Space :47A:0329 :3:Space After the... (2 Replies)
Discussion started by: API
2 Replies
All times are GMT -4. The time now is 07:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy