Need to change two words in a line using shell script.

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to change two words in a line using shell script.
# 1  
Old 08-24-2009
Need to change two words in a line using shell script.

i have a line
tftp          dgram   udp      wait    nobody  /usr/sbin/tcpd  in.tftpd  /tftpboott

in /etc/inet.conf file. ineed to replace nobody with root and /tftpboott with /flx/boot. i tried using sed ,but i could not change both of them. can you please help me to do this.

Edit: Next time use [code] and [/code] tags when displaying code, data or logs etc. to enhance readability and preserve formatting like indention etc., ty.

Last edited by zaxxon; 08-24-2009 at 04:55 AM.. Reason: code tags
# 2  
Old 08-24-2009
sed 's/\/tftpboott/\/flx\/boot/; s/nobody/root/'

# 3  
Old 08-24-2009
This will replace nobody to root in other lines also,but i want to replace nobody to root in those lines containing /tftpboott
# 4  
Old 08-24-2009
That's true. Try this:
sed '/tftpboott/ { s/\/tftpboott/\/flx\/boot/; s/nobody/root/}' infile

# 5  
Old 08-24-2009
sed '/nobody.*\/tftpboott$/ { s/\/tftpboott/\/flx\/boot/; s/nobody/root/}' /etc/inet.conf

i think this is more secure
# 6  
Old 08-25-2009
Is it possible to change only the first line which has tftpd leaving other lines which may have tftpd.can u pls share the code snippet and can i pass the pattern to be replaced by a variable?

Last edited by vprasads; 08-25-2009 at 04:43 PM..
# 7  
Old 08-26-2009
Post an your complete example of your input so we don't have to guess around and mark the line you want to have to be changed. Use [code] and [/code] tags when doing so, thank you!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace particular words in file based on if finds another words in that line

Hi All, I need one help to replace particular words in file based on if finds another words in that file . i.e. my self is peter@king. i am staying at north sydney. we all are peter@king. How to replace peter to sham if it finds @king in any line of that file. Please help me... (8 Replies)
Discussion started by: Rajib Podder
8 Replies

2. Shell Programming and Scripting

Search words in any quote position and then change the words

hi, i need to replace all words in any quote position and then need to change the words inside the file thousand of raw. textfile data : "Ninguno","Confirma","JuicioABC" "JuicioCOMP","Recurso","JuicioABC" "JuicioDELL","Nulidad","Nosino" "Solidade","JuicioEUR","Segundo" need... (1 Reply)
Discussion started by: benjietambling
1 Replies

3. Shell Programming and Scripting

Stemming of words that contained affixes by using shell script

I just learning shell script. Need your shell script expertise to help me. I would like to stemming the words by matching the root words first between both files and replace all words by "I" character but replace "B" character after root words and "E" before root words in affix_words.txt. ... (18 Replies)
Discussion started by: paranrat
18 Replies

4. Shell Programming and Scripting

Shell script to read words into an array

Hello, I have output like below: ----------------------------------------------------------------------------- Group 'group1' on system 'system01' is running. ----------------------------------------------------------------------------- Group 'group2' on system 'system01' is running.... (4 Replies)
Discussion started by: sniper57
4 Replies

5. Shell Programming and Scripting

shell script to print words having first and last character same.

Hi I want to write a shell script to print only those words from a file whose beginning and last character are same. Please help. Thanks, vini (5 Replies)
Discussion started by: vini kumar
5 Replies

6. Shell Programming and Scripting

Shell script to find out words, replace them and count words

hello, i 'd like your help about a bash script which: 1. finds inside the html file (it is attached with my post) the code number of the Latest Stable Kernel, 2.finds the link which leads to the download location of the Latest Stable Kernel version, (the right link should lead to the file... (3 Replies)
Discussion started by: alex83
3 Replies

7. Shell Programming and Scripting

how to shift few words of filenames at a time using shell script

Hello everybody, I have some files in directory. I want to shift 3 characters of filenames to the right at a same time. for example, I have filenames like $ls -l 01_2000.G3.input.txt 02_2000.G3.input.txt ..., ..., 04_2010.G3.input.txt I want to change the filenames like... (3 Replies)
Discussion started by: yogeshkumkar
3 Replies

8. Shell Programming and Scripting

Change a line in a php file thanks to a shell script

Hi, I'm working on a script to make automatic the new releases of my website... However in this script I put all the css script in a single one. There's no rpoblem for that. My problem is when I want to change the header of my layout page to put instead of : $header.="<link rel=\"stylesheet\"... (2 Replies)
Discussion started by: lahabana
2 Replies

9. Shell Programming and Scripting

how to retrieve the word between 2 specific words with shell script

Hi, I have a file content like: : : <span class="ColorRed"> 1.23</span><br> : : the value 1.23 will be changed from time to time, and I want to use a shell script command, e.g grep or sed, to retrieve only the value, how to do it? Thanks! Victor (6 Replies)
Discussion started by: victorcheung
6 Replies

10. Shell Programming and Scripting

Script to change file contents line by line

Hi, I'm struggling to write a script to do the following, -will go through each line in the file -in a specific character positions, changes the value to a new value -These character positions are fixed througout the file ----------------------- e.g.: will have the following 3... (4 Replies)
Discussion started by: vini99
4 Replies
Login or Register to Ask a Question