Add a word after a specific patter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add a word after a specific patter
# 1  
Old 09-16-2013
Add a word after a specific patter

Hi,

I have file like below .
Code:
export Var1=
export Var2=
export Var3=test

Now i want to add a word "adm1" after Var1= and adm2 after Var2=
Code:
export Var1=adm1
export Var2=adm2
export Var3=test

Can some one please help me the command to acheive the above output.

Thanks

Last edited by Scott; 09-16-2013 at 05:04 AM.. Reason: Code tags
# 2  
Old 09-16-2013
Code:
 sed 's/Var1.*/&adm1/; s/Var2.*/&adm2/' infile

--ahamed
# 3  
Old 09-16-2013
Code:
awk '/Var1/{$NF=$NF"adm1"} /Var2/{$NF=$NF"adm2"} 1' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to get word after a specific word

Hi, I need hostname from below entry.How do I write a script on this?tnsping is utility in oracle -if I do tnsping ora11gb then it would give one output and I want to extract hostname from this output which come after "HOST=" oracle@brookford:~> tnsping ora11gb|grep -i HOST Attempting to... (11 Replies)
Discussion started by: admin_db
11 Replies

2. Shell Programming and Scripting

Search for a specific word and print only the word from the input file

Hi, I have a sample file as shown below, I am looking for sed or any command which prints the complete word only from the input file. Ex: $ cat "sample.log" I am searching for a word which is present in this file We can do a pattern search using grep but I need to cut only the word which... (1 Reply)
Discussion started by: mohan_kumarcs
1 Replies

3. Shell Programming and Scripting

How to print multiple specific column after a specific word?

Hello.... Pls help me (and sorry my english) :) So I have a file (test.txt) with 1 long line.... for example: isgc jsfh udgf osff 8462 error iwzr 653 idchisfb isfbisfb sihfjfeb isfhsi gcz eifh How to print after the "error" word the 2nd 4th 5th and 7th word?? output well be: 653 isfbisfb... (2 Replies)
Discussion started by: marvinandco
2 Replies

4. Shell Programming and Scripting

Need a word which just comes next to after grep of a specific word

Hi, Below is an example : ST1 PREF: int1 AVAIL: int2 ST2 PREF :int1 AVAIL: int2 I need int1 to come in preferred variable while programming and int2 in available variable Please help me doing so Best regards, Vishal (10 Replies)
Discussion started by: Vishal_dba
10 Replies

5. UNIX for Dummies Questions & Answers

Quick UNIX command to display specific lines in the middle of a file from/to specific word

This could be a really dummy question. I have a log text file. What unix command to extract line from specific string to another specific string. Is it something similar to?: more +/"string" file_name Thanks (4 Replies)
Discussion started by: aku
4 Replies

6. Shell Programming and Scripting

Fetch entries in front of specific word till next word

Hi all I have following file which I have to edit for research purpose file:///tmp/moz-screenshot.png body, div, table, thead, tbody, tfoot, tr, th, td, p { font-family: "Liberation Sans"; font-size: x-small; } Drug: KRP-104 QD Drug: Placebo Drug: Metformin|Drug:... (15 Replies)
Discussion started by: Priyanka Chopra
15 Replies

7. 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

8. Shell Programming and Scripting

Grep out specific word and only that word

ok, so this is proving to be kind of difficult even though it should not be. say for instance I want to grep out ONLY the word fkafal from the below output, how do I do it? echo ajfjf fjfjf iafjga fkafal foeref afoafahfia | grep -w "fkafal" If i run the above command, i get back all the... (4 Replies)
Discussion started by: SkySmart
4 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