Using sed to replace a word at specific location


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using sed to replace a word at specific location
# 8  
Old 01-18-2013
That is so unfortunate for me, but I tried replacing -i with -e and even trail and error with single and double quotes, it never worked. Is there any other way to solve this problem? I even tried awk as above but it didn't changed the content at all.
# 9  
Old 01-18-2013
Quote:
Originally Posted by pjeedu2247
That is so unfortunate for me, but I tried replacing -i with -e and even trail and error with single and double quotes, it never worked. Is there any other way to solve this problem? I even tried awk as above but it didn't changed the content at all.

Are you running this in linux sever only,right?

which flavour of linux you are using. "-i" command is the well known command to me..am using this from past 3 yrs.
# 10  
Old 01-18-2013
I'm trying that on aix. My bad, to say that so late. I thought you might know that my seeing probhit to aix.
# 11  
Old 01-18-2013
Quote:
Originally Posted by pjeedu2247
I'm trying that on aix. My bad, to say that so late. I thought you might know that my seeing probhit to aix.

we have some minor differences for linux to aix.

I dont have aix server now to check, please try like this hope it will work fine to you.

Code:
sed  "/ssh\|emagent/s/prohibit/aix/g" /etc/pam.conf > output_file

(at the same time try with single quotes)

---------- Post updated at 12:56 AM ---------- Previous update was at 12:51 AM ----------

Quote:
Originally Posted by srinivas matta
we have some minor differences for linux to aix.

I dont have aix server now to check, please try like this hope it will work fine to you.

sed "/ssh\|emagent/s/prohibit/aix/g" /etc/pam.conf > output_file

(at the same time try with single quotes)

I am sure single code will work in aix.

Code:
sed '/ssh\|emagent/s/prohibit/aix/g' /etc/pam.conf > output_file

Have a good time.

Last edited by Scott; 01-18-2013 at 03:12 AM.. Reason: Code tags
# 12  
Old 01-18-2013
I'm sorry to say this, but still unable to change the content. Smilie
# 13  
Old 01-29-2013
Please try below two commands one with single quote and another with double quote and these commands will replace prohibit with aix word for the lines which are starting with ssh or emagent.

Note :- below commands will replace the lines starting with ssh and emagent only not with sshd. if you want to replace with sshd also please remove the space after "ssh" in the command.



Code:
  sudo sed "/^ssh \|^emagent/s/prohibit/aix/g"  filename

Code:
 sudo sed '/^ssh \|^emagent/s/prohibit/aix/g' filename

Best Regards,
Kalyan

Last edited by Kalyan507; 01-29-2013 at 03:01 AM..
# 14  
Old 01-29-2013
Thank you, it worked.
This User Gave Thanks to pjeedu2247 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy files based on specific word in a file name & its extension and putting it in required location

Hello All, Since i'm relatively new in shell script need your guidance. I'm copying files manually based on a specific word in a file name and its extension and then moving it into some destination folder. so if filename contains hyr word and it has .md and .db extension; it will move to TUM/HYR... (13 Replies)
Discussion started by: prajaktaraut
13 Replies

2. Shell Programming and Scripting

Deleting lines in a fixed length file where there is a word at specific location

I have a big file having 100 K lines. I have to read each line and see at 356 character position whethere there is a word "W" in it. If it is their then don't delete the line otherwise delete it. There are two lines as one Header and one trailer which should remain same. Can somebody... (5 Replies)
Discussion started by: mohit kanoongo
5 Replies

3. Shell Programming and Scripting

How to find a word and move it a specific location in xml file using perl?

Hi friends, I have one XML file having below structure :- INput XML file :- <?xml version="1.0" encoding="UTF-8"?> <START> <A=value1> <attr name1="a1"> </A> <B=value2> <attr name2="b1"> <attr name3="c1"> </B> </START> output xml file should be === (3 Replies)
Discussion started by: harpal singh
3 Replies

4. Shell Programming and Scripting

Replace spaces at a specific Location

Hello All, I have a comma separated file which needs to be loaded to the database. But, I need to trim the white spaces for a specific column before its loaded. Below is the sample line from the input file: 690,690,0575,"01011940","01011940", , , , , ,36720,36722,V2020,V2999,... (6 Replies)
Discussion started by: Praveenkulkarni
6 Replies

5. UNIX for Dummies Questions & Answers

How to print line starts with specific word and contains specific word using sed?

Hi, I have gone through may posts and dint find exact solution for my requirement. I have file which consists below data and same file have lot of other data. <MAPPING DESCRIPTION ='' ISVALID ='YES' NAME='m_TASK_UPDATE' OBJECTVERSION ='1'> <MAPPING DESCRIPTION ='' ISVALID ='NO'... (11 Replies)
Discussion started by: tmalik79
11 Replies

6. Shell Programming and Scripting

Help with replace character based on specific location

Hi, I got long list of reference file (column one is refer to the header in input file; column 2 is info of start position in input file; column 3 is info of end position in input file;) shown as below: read_2 10 15 read_3 5 8 read_1 4 10 . . . Input file (huge file with total... (6 Replies)
Discussion started by: perl_beginner
6 Replies

7. Shell Programming and Scripting

Find and replace a string a specific value in specific location in AIX

Hi, I have following samp.txt file in unix. samp.txt 01Roy2D3M000000 02Rad2D3M222222 . . . . 10Mik0A2M343443 Desired Output 01Roy2A3M000000 02Rad2A3M222222 . . (5 Replies)
Discussion started by: techmoris
5 Replies

8. Shell Programming and Scripting

Finding a word at specific location in a string

Hi All , I have different strings (SQL queries infact) of different lengths such as: 1. "SELECT XYZ FROM ABC WHERE ABC.DEF='123' " 2. "DELETE FROM ABC WHERE ABC.DEF='567'" 3. "SELECT * FROM ABC" I need to find out the word coming after the... (1 Reply)
Discussion started by: swapnil.nawale
1 Replies

9. Shell Programming and Scripting

how to Add word at specific location in line

eg . i have file x.txt contains : java coding , shell scriptting etc... now i want to add "is langauge" after word java. output should be java is langauge coding , shell scriptting etc... any idea how to use shell script to do it ? (10 Replies)
Discussion started by: crackthehit007
10 Replies

10. Shell Programming and Scripting

How to replace a specific word in specific column?

Hi My orginal file is like (100s of lines) id host ip location remarks 1 host1 ip1 - xxx 2 host2 ip2 - xxx 3 host3 ip3 - xxx -- -- 9 host9 ip9 - xxx I have a ref file like host1 location1 host2 location2 host3 location3 -- --... (6 Replies)
Discussion started by: ./hari.sh
6 Replies
Login or Register to Ask a Question