replace part of text of a line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting replace part of text of a line
# 1  
Old 05-13-2010
replace part of text of a line

Gurus,
You know, I believe you do:-), the comnand uname -r give you the kernel version:

Code:
serverA:~# uname -r
2.6.26-1-xen-amd64

So, I want to replace this output inside in the line below that is inside the file:

Code:
kernel = '/boot/vmlinuz-2.6.26-1-xen-amd64'

Suppose, you move this file to ther server with another kernel:

Code:
serverB:~# uname -r
2.6.26-2-xen-amd64

Question, how can I replace the line to fit the new version? Like this:

Code:
kernel = '/boot/vmlinuz-2.6.26-2-xen-amd64'

regards,
Israel.
# 2  
Old 05-13-2010
Something like this?
Code:
sed "/kernel =/s/-.*/-`uname -r`'/" file > newfile

# 3  
Old 05-13-2010
perfect!!

really appreciate Franklin.. :-)

regards
Israel
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace text/string with new line

Hello All I have had a requirement where I need to move data to a new line based on a text Input :61: 456 B66666 :61: 878 N78777 :61: 534533534 BNNN Output :61: 456 B66666 :61: 878 N78777 :61: 534533534 BNNN So basically as soon as it encounters :61: it should... (3 Replies)
Discussion started by: kamijia83
3 Replies

2. Shell Programming and Scripting

sed - How to replace right part of equal sign (=) on a line

Hello. Using a bash script , I have a variable name for the file I want to modify FILE_TO_EDIT="/etc/my_config_file"And I have a variable name for the parameter to change PARAMETER="fallback_node" PARAMETER_NEW_VALUE="http://my_server_name.com/new_path" A config file may contain : 1°)... (2 Replies)
Discussion started by: jcdole
2 Replies

3. Shell Programming and Scripting

Reading text file, comparing a value in a line, and placing only part of the line in a variable?

I need some help. I would like to read in a text file. Take a variable such as ROW-D-01, compare it to what's in one line in the text file such as PROD/VM/ROW-D-01 and only input PROD/VM into a variable without the /ROW-D-01. Is this possible? any help is appreciated. (2 Replies)
Discussion started by: xChristopher
2 Replies

4. Shell Programming and Scripting

Shell script - Replace just part of a single line in a file.....

Hey guy's.... I new here, But im working on a school project, and I am not really good at programming. In fact, this is the only programming class that I need because programming is not what I am majoring in. But I have everything done in this shell script except for this last part..... ... (9 Replies)
Discussion started by: hxdrummerxc
9 Replies

5. UNIX for Dummies Questions & Answers

Parse out part of line in text document

I have an XML file that I am attempting to create a new text document from it with only one of the pieces of data printed. Here's an example: Source: <?xml version="1.0"?> <Reply Success="TRUE"> <ProfileList NrOfProfiles.DWD="645"> <Profile_0 Name="Test" Description="A... (3 Replies)
Discussion started by: Davinator
3 Replies

6. Shell Programming and Scripting

Finding a string in a text file and posting part of the line

What would be the most succinct way of doing this (preferably in 1 line, maybe 2): searching the first 10 characters of every line in a text file for a specific string, and if it was found, print out characters 11-20 of the line on which the string was found. In this case, it's known that there... (13 Replies)
Discussion started by: busdude
13 Replies

7. UNIX for Dummies Questions & Answers

how to replace a text of line with a comment line

I want to replace this line : "test compare visible] true" and make it "#test compare visible] true". How can I do it ? And it should be checked in many sub folder files also. (6 Replies)
Discussion started by: manoj.b
6 Replies

8. Shell Programming and Scripting

Replace part of a line with sed/awk

Hello I have a document and in this document I have several occurrence of "VAR == xxxxxxx" and xxxxx can be anything. I don't know what it is. I want to replace the 'xxxxx's with something I know. What I know however, is the line numbers of the VAR =='s in the file. How can I replace... (1 Reply)
Discussion started by: alirezan
1 Replies

9. Shell Programming and Scripting

Replace Entire line if any part matches regexp

Hey guys, I have a file that I've slowly been awking, seding, and greping for data entry. I am down to pull the addresses out to insert them into an excel file. Each address is a few lines, but i want to put a semicolon delimiter in between each address so I can export the text file into excel and... (6 Replies)
Discussion started by: Cocoabean
6 Replies

10. UNIX for Dummies Questions & Answers

Replace line of text in a file

I need to change the first line a file from "HDR,{any_number}",,,,, where {any_number} is incremental for each file to HDR,{any_number} Can someone please suggest an easy way please Regards Col (3 Replies)
Discussion started by: colinchase
3 Replies
Login or Register to Ask a Question