Fedora :: Replace A Certain Line Of A File With A Variable?

Nov 26, 2009

I want to replace a certain line of a file, my bash script looks like:

#!/bin/sh
sentence="if [ -e /home/inf/Download/$playlist ]"
sed '4c
$sentence' oldfile > newfile
mv -f newfile oldfile

But the variable $sentence can not be identified in ' ' . And also you can see I just want to update the old file. But the sed command can not save the file for me ,so I need to write them to a new file and over write the new file .

View 14 Replies


ADVERTISEMENT

Programming :: Sed Script - Searching For Text Within File / Replace With Variable

Feb 25, 2011

Code:
#!/bin/bash
VARR=`cat /proc/asound/cards | grep HDMI | cut -c 1-2`
VARX="defaults.ctl.card $VARR"
VARY="defaults.pcm.card $VARR"
FILE1="alsa"
FILE2="alsa.new"
echo $VARX
echo $VARY
sed "s/defaults.ctl.card*/'$VARX'/g" $FILE1 > $FILE2

This is what I have right now. Well, I thought I knew sed, and apparently I don't... I tried writing this for someone else, and this has given me trouble, so since the user pretty much figured it out on his own, here it goes.
Say VARR=1, so VARX and VARY contain the above text, appended by 1.
What I am trying to do is replace the text "defaults.ctl.card 0" by VARX and "defaults.pcm.card 0" by VARY. The contents of FILE1 is the file being used to search for both text fields, and FILE2 is the output file. I tried using single quotes, double quotes, and a mixture of both, and no go whatsoever. So my question... What is the proper way of searching for text within a file and replacing with a variable?

View 5 Replies View Related

General :: Replace One Line For Another In File?

Dec 1, 2010

I trying to change a file with hundreds of entries, replacing line with "IP Address Number" for "Host Name", one for another.

this is the original: [IP Address Configuration : "172_17_27_161.SUBNET_U"] IP Address Number = 172.17.27.161Assignment Type = 8Host Name = CAST124Last Used = 1290499294000MAC Address = 1 00 16 35 74 4C 59Client Identifier = 01 00 16 35 74 4C 59and the result desired is: [IP Address Configuration : "172_17_27_161.SUBNET_U"]Host Name = CAST124Assignment Type = 8IP Address Number = 172.17.27.161Last Used = 1290499294000MAC Address = 1 00 16 35 74 4C 59Client Identifier = 01 00 16 35 74 4C 59I know how to change one character by another with sed, but not to change a line for another, because I don't know in which line number it is.

View 3 Replies View Related

General :: Ubuntu - Replace A File In Jar With Command Line ?

Oct 18, 2010

I have a jar, and I need to replace a class in it, at this moment, I can only open it with "archive manager" and then drag and drop the new compiled class into the jar, but I think this is really boring, if I can do with with just a command ?

View 1 Replies View Related

Programming :: Shell Script Replace A Line From A File?

Mar 4, 2010

I am beginner in this business of shell script and I have no idea how to do the following: I would like to replace the lines of my file that contains 'CFL=' by 'CFL=0.5'. Note that I want to replace the full line meaning

View 11 Replies View Related

General :: Replace Nth Occurence Of String In Each Line Of A Text File?

May 20, 2010

I have large text files with space delimited strings (2-5). The strings can contain "'" or "-". I'd like to replace say the second space with a pipe. What's the best way to go?
Using sed I was thinking of this:

sed -r 's/(^[a-z'-]+ [a-z'-]+) /1|/' filename.txt

View 2 Replies View Related

Programming :: Looping Using While Read Line And A Variable Instead Of A File?

Sep 24, 2010

I created the following.

x="top
middle
bottom"

I would like to make the following work.

while read line
do
echo $line
done

instead of importing a file I would like to use the variable $x I tried using pipes, but with no luck. My goal is to read one line at a time, but not have to export my data to another file, I would like to keep it all within one script.

View 3 Replies View Related

General :: Script To Traverse Into Sub-directory And Replace Line Of File Inside Zip?

Aug 27, 2010

I can't get sed to actually change the file, clearly there's something basic not working, can anyone point me in the right direction? I know nothing about scripting. Oh yeah, all the directories have spaces which was why so elaborated.

find . -name "*epub" | while read file; do unzip -o "$file" content.opf && mv content.opf content.opf.bak && sed 's/<dc:language>UND</dc:language>/<dc:language xsi:type="dcterms:RFC4646">EN</dc:language>/' < content.opf.bak > content.opf && zip "$file" content.opf && rm -f content.* ; done

View 2 Replies View Related

Programming :: Insert Line Using Sed Or Awk At Line Using Line Number As Variable

Jul 25, 2011

I want to insert a line at a particular line number using sed or awk. where line number is not fixed and is in form of variable.

I want to use variable in sed or awk command.I tried something like below, but no luck.

View 7 Replies View Related

Red Hat / Fedora :: Yank (and Even Cooler Replace) A Line In A Bunch Of Files?

Jun 27, 2011

I have a file that is in almost all my /home web accounts, here: /home/accountXXXX/public_html/cms3.0.php in that file is a line I want to get rid of: <script id="jslocal" language="JavaScript" type="text/javascript" src="/site-local/local.js"></script>

is there a simple shell script that would recurse all /home/xxx/public_html directories, and then yank this line (it will always be exactly the same) and better yet, for future, is there any way I can REPACE that line with another..

View 2 Replies View Related

Programming :: Perl Script To Replace Line After Finding Previous Line

Feb 28, 2011

At the moment I have a flat file which is being used by a few people. I want a script to remotely change the file, so I can start logging who is doing what.At this point here is one requirement I am trying to develop. We have text blocks who pretty much look like.I hope this is somewhat clear. I try to find $param for the right $workflow and change that. Can you help me to find $$var3 and change that?

View 1 Replies View Related

Software :: Grep Query To List 1 Line (which Is Fixed) And The Next Line After It (variable Text)

Jan 20, 2011

How can I list the following with grep. I want to extract 2 lines fron a text file The fixed known part if it exists will static text and the text line after it will change.

A sample file
.
.
textline1

[code]....

If the fixed part does Not exist how can I return error code 1

View 3 Replies View Related

Programming :: Search A File For A Particular Pattern And If Pattern Found Replace The Line With New Text?

Feb 24, 2010

I want to search a file for a particular pattern and if pattern found replace the line with new text. i am using awk 'match($0,"pattern") != 0 {print $0} ' filename to check if the pattern exists.how do i get the line number of the pattern and delete that line and replace the line with my new text?

View 1 Replies View Related

Ubuntu :: Replace In The Xorg.conf File The Line In The Section "Device"

Nov 10, 2010

I have a Dell precision M50 which has the NVIDIA Quadro4 500 GoGL. When I upgraded from 10.04 to 10.10 the proprietary NVIDIA driver stopped working. At that time I found a simple solution which was to replace in the xorg.conf file the line in the Section "Device":

[Code]...

View 6 Replies View Related

General :: Replace Line With Another Line In Shell Script?

Feb 26, 2010

I have the file abc.txt

cat abc.txt This is a test file Nothing is new in this world

I want to replace "This is a test file" to "Text is replaced"

Code:
FindString='This is a test file'
ReplaceString='Text is replaced'
Findarray=(`echo $FindString | tr ' ' ' '`)

[Code]....

But this is not effective. how to replace entire line either using sed or awk or any other utility.

View 5 Replies View Related

Fedora :: Adding Variable Command Line Parameters To Desktop Launchers?

Mar 15, 2010

I have added an application launcher to my desktop and it works fine. However, I want to be able to feed parameters to the launcher before I launch the application. So, for instance, if the command is normally "/usr/bin/foo something" I want to be able to add the "something" parameter dynamically after clicking the launcher but before the application launches. Is this possible in Fedora?

View 2 Replies View Related

General :: Using Sed To Send A Variable And Replace?

Oct 6, 2010

I can't figure out the exact sed to make this work. I've installed CentOS and am trying to pass variables to a network-config file.

variables:
$ipAddress
$netmask

[code]...

View 1 Replies View Related

Programming :: Make Bash Replace The Value Of A Variable?

Apr 18, 2009

I have a program I am writing where I have a for loop and I want to make it substitute the variable twice like:

for ((i=0;i<5;i++)) do
echo $"$i"
done

[code]...

View 3 Replies View Related

General :: Text Manipulation Find / Replace Variable Efficiency?

Aug 27, 2010

What I have works, but wondering what is the 'right' way to replace the digits with the letters given in this loop? somehow use a case or multiple sed? i thought of a multiple sed or a case but couldn't get it to work

Code:

# ...
bcv=$(echo $line | awk -F" " '{ print $1 }' | sed 's/1/q/g;s/2/w/g;s/3/e/g') # and so on

Code:

while read line
do
bcv=$(echo $line | awk -F" " '{ print $1 }')
if [ $bcv == "" ]

[code].....

View 12 Replies View Related

Programming :: Bash - Read Content Of File To Variable And Use This Variable In For Loop ?

Aug 21, 2009

I'm trying to read content of file to variable and use this variable in for loop. The problem is, when I have c++ comment style in file - /*. Spaces in line are also interpreted as separated lines.

For example:

Code:

Changing $files to "$files" eliminate these problems but causes that whole content of variable is treated as one string (one execution of loop).

View 6 Replies View Related

Software :: Get Variable From Text File Into Bash Variable?

Jun 10, 2009

I have a text file i that has a mailTo: NAME in it. In a bash script i need to extract NAME and put it in a $variable to use. How do i do this?

View 2 Replies View Related

Programming :: Replace An "entire" Line Containing A Particular String With A New Line?

Mar 12, 2010

I think this can be done using sed. Let's say I have file called, "orig.txt" with following contents:

Code:
[User Prefs]
Ignore Unrequested Popups=1
DevTools Splitter Position=500
History View Style=0

[Code]....

So basically if a line contains the word "Home URL" then go ahead and replace that *entire* line with the supplied *new* line.

View 4 Replies View Related

Fedora :: Conditionally Replace An HTML Tag In A Large File?

Mar 28, 2011

We receive this large file which is generated as a HTML page.So anybody can view it with a web brower.A few lines from this file ...

Code:
<tr><td><font color="#555555" size="3" face="Tahoma, Arial, Verdana, Helvetica"> 1999 <font color="#cc6600" size="5">←</font> <font color="#0066ff" size="4">03</font>-27

[code]...

View 8 Replies View Related

Red Hat / Fedora :: Can't Use It For Creating A Path Variable / File Name?

Mar 15, 2010

Originally Posted by Gekitsuu you should be able to do NEWSTRING=$STRING1$STRING2 it works but i can't use it for creating a path variable / file name.

e.g.
$STRING1 = path
$STRING2 = filename
cat $STRING1$STRING2 will not work.
so how to get this working?

View 4 Replies View Related

Ubuntu :: Replace A Line Containing Particular String Using Sed?

Oct 16, 2010

How to replace a line containing some word by only another word...

Ex: The sed program is the Linux stream editor utility The pattern is a regular expression that you wish to match and replacement is the new string to ..

replace the line containing 'program' by only word LINUX

View 1 Replies View Related

General :: Vim Replace All The Same Words In A Certain Line?

Dec 2, 2010

15 for(i = 0; i < N; i++) I want to replace "i" with "test" in the line above,whose line number is 15. When I tried this command :15s/i/test/ Line 15 turned to be this: for(test = 0; i < N; i++) It only replace the first "i",but I want to change all "i" in line 15.

View 3 Replies View Related

Programming :: Access A File Line By Line, And Check The Length Of Each Line.

Feb 13, 2011

I want to access a file, and check the length of every line.After, i want to check and replace all lines with length over 10 characters, with a message.Does anyone have a clue on that?

View 1 Replies View Related

Programming :: Awk Multiple Line Search And Replace?

May 1, 2011

I am trying to search and replace a multi line pattern in a php file using awk.The pattern starts with

<div id="navbar">
and ends with
</div>

[code]...

View 3 Replies View Related

General :: Replace Multiple Instances From X To Y In Line

Feb 1, 2010

I have a line of text with multiple web links in the line. I'd like to replace the actual links with the text "<web-link>" so I don't accidentally hit them while reading on my iphone. I've tried many versions of the following sed command, sed 's/(http.*)/<web_link>/g', but it simply replaces everything between the first instance of "(http" and the last instance of ")" with <web_link>, or does nothing at all.

Ex: This line has a link to a web page (http://www.webpage.com/file.html) then some more text (extra text) and then another link (http://www.nextwebpage.com.index.html) to a website.
$ echo "This line has a link to a web page (http://www.webpage.com/file.html) then some more text (extra text) and then another link (http://www.nextwebpage.com.index.html) to a website." | sed 's/(http.*)/<web_link>/g'

What I get is: This line has a link to a web page <web_link> to a website.
What I'd like is: This line has a link to a web page <web_link> then some more text (extra text) and then another link <web_link> to a website.
What am I doing wrong with my sed command?

View 4 Replies View Related

Programming :: Replace A Complex Line In Lvm.conf

May 19, 2011

I need to replace a line in the lvm.conf file from: filter = [ "r|/dev/.*/by-path/.*|", "r|/dev/.*/by-id/.*|", "a/.*/" ] to: filter = [ "a|/dev/cciss/c0d0.*|", "a|/dev/disk/by-id/.*|", "r|.*|" ] And I was hoping there was a way to use sed or awk to do this in a script (as I need to repeat this on several machines).

All of the examples I've found don't see to work with all of the special characters in the line that I need to replace. Then I need to add a line after the above edit like this: types = [ "device-mapper", 253 ]

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved