Replace a String using Bash


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Replace a String using Bash
# 1  
Old 05-02-2012
Replace a String using Bash

I'm going freakin crazy here! I've tried multiple attempts and configurationa and cannot get this to work.

I have a file:
Code:
private/etc/apt/sources.list.d/cydia.list

I want to replace a string in this file:
Code:
"deb http:name.of.address ./"

with
Code:
"deb http:name.of.other.address ./"

The 'cydia.list' file permissions (I'm not the owner) are:
Code:
-rw-r-r- root wheel

Can I edit this file and, if so, how can I do it cuz everything i've tried hasn't worked....Smilie

Thanx in advance!!!

Last edited by Scrutinizer; 05-02-2012 at 11:20 AM.. Reason: code tags
# 2  
Old 05-02-2012
You do not have permissions to change that file...
# 3  
Old 05-02-2012
I was afraid of that...

For fun, I tried this script and it worked!!! ...but I don't why it worked...

Code:
mv /private/etc/apt/sources.list.d/tortrix.list /private/etc/apt/sources.list.d/cydia.list

The contents of 'tortrix.list' wrote over the contents of 'cydia.list' even though I shouldn't be able to, right?

If it is possible, could I construct something to extract the contents of 'Cydia.list' and make a new copy of it???

Last edited by Scrutinizer; 05-02-2012 at 11:40 AM.. Reason: code tags
# 4  
Old 05-02-2012
Probably you do have write access to the directory in which it resides and so you can remove the old file probably you were given a warning?

Have look at the directory permissions:
Code:
ls -ld /private/etc/apt/sources.list.d

--
Please view this link to learn the use of code tags.
# 5  
Old 05-03-2012
Thanx, bud! Now, I understand why one thing worked but the other will not... I appreciate ur help and I should've asked this before spending hours and hours trying to solve it myself! LOL!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search partial string in a file and replace the string - UNIX

I have the below string which i need to compare with a file and replace this string in the file which matches closely. Can anyone help me on this. string(Scenario 1)- user::r--,user::ourfrd:r-- String(Scenario 2)- user::r-- File **** # file: /local/Desktop/myfile # owner: me # group:... (6 Replies)
Discussion started by: sarathy_a35
6 Replies

2. Shell Programming and Scripting

[bash] - Replace blank and string in csv file

Hi all, i have a .csv file with only two columns, like: Login;Status Luca;S Marco; Stefano; Elettra;S Laura; ... I need to replace the blank space on Status column whit Enabled end, on the same column, S whit Disabled, like: Login;Status Luca;Disabled Marco;Enabled Stefano;Enabled... (10 Replies)
Discussion started by: kamose
10 Replies

3. UNIX for Advanced & Expert Users

BASH Internal : Replace pattern with string without external command

Morning, I'm trying step up my scripting game .. :rolleyes::confused::D Is there a way to do the replacement with an or without using an external command ? I did try but no joy. var=${var//\(|\)/} #!/bin/bash var="lulus.UbiRwidgets.com (10.1.1.1)" var=${var//\(/}... (5 Replies)
Discussion started by: popeye
5 Replies

4. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

5. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

6. Shell Programming and Scripting

Requesting help to replace a string by my bash script

Hello every1, I need help to replace a string in a file by my bash script. Find: log4j.appender.toLogFile.layout.ConversionPattern= %d %5p (%F:%L) - %m%n= %d %5p (%F:%L) - %m%n Replace: log4j.appender.toLogFile.layout.ConversionPattern= %d %5p (%F:%L) - %m%n I tried by sed, but kept... (7 Replies)
Discussion started by: titanic4u
7 Replies

7. Shell Programming and Scripting

Using sed to replace a string in file with a string in a variable that contains spaces

Hi, i call my shell like: my_shell "my project name" my script: #!/bin/bash -vx projectname=$1 sed s/'PROJECT_NAME ='/'PROJECT_NAME = '$projectname/ <test_config_doxy >temp cp temp test_config_doxy the following error occurres: sed s/'PROJECT_NAME ... (2 Replies)
Discussion started by: vivelafete
2 Replies

8. Shell Programming and Scripting

Bash string replace

Bash shell. I'm trying to filter a string taken from user input. I can replace one word at a time. This method supports regex, so is it possible to replace various words at a time? STRING="Hello World! word1 word2"; FILTERED=${STRING/word1|word2/}; # Not working: replace 2 or more words ??? ... (10 Replies)
Discussion started by: limmer
10 Replies

9. Shell Programming and Scripting

awk - replace number of string length from search and replace for a serialized array

Hello, I really would appreciate some help with a bash script for some string manipulation on an SQL dump: I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump. This is quite easy with sed: sed -e... (1 Reply)
Discussion started by: otrotipo
1 Replies

10. Shell Programming and Scripting

Search, replace string in file1 with string from (lookup table) file2?

Hello: I have another question. Please consider the following two sample, tab-delimited files: File_1: Abf1 YKL112w Abf1 YAL054c Abf1 YGL234w Ace2 YKL150w Ace2 YNL328c Cup9 YDR441c Cup9 YDR442w Cup9 YEL040w ... File 2: ... ABF1 YKL112W ACE2 YLR131C (9 Replies)
Discussion started by: gstuart
9 Replies
Login or Register to Ask a Question