Replacing set of characters with a value of a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing set of characters with a value of a variable
# 1  
Old 07-26-2005
Replacing set of characters with a value of a variable

I need to replace anything immediately after the pattern "standard01/" in a file with the value of a variable
I don't know the length of the characters stored in that variable. - that might vary.
I know there is some string after the pattern "standard01/", i don't know the what the string is or the length of it. but i know after that string following "standard01/", there is blank space and after that a word called "buf" in that file

So, the string following the pattern "standard01/" for example looks like
"special_previlege_datetime.lst" followed by a space and then a string begins with "buf" - when in the process of replacing the value of the variable right after the above pattern "standard01/" - i should not start overwriting the next string "buf"
- in other words i should try to replace/write the value of the variable starting
immediately after "standard01/" and before the next word "buf" begins.

Please provide your advice.
Your help is greatly apprecitaed.
Thanks
# 2  
Old 07-26-2005
a way is: sed -i 's/standard01\/ .* buf/standard01\/ NUMBER buf/g' file.in
if you guarantee that all characters between the standard01/ and buf are digits, you can use: sed -i 's/standard01\/ [0-9]* buf/standard01\/ NUMBER buf/g' file.in
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Replacing characters in a file

Suppose I have a file which has 1000 columns (5 SHOWN FOR EXAMPLE) two alphabets are separated by a space and then tab A A"\t"C C"\t"G G"\t"0 0"\t"T T A G"\t"C C"\t"G G"\t"A T"\t"0 0 G A"\t"0 0"\t"G C"\t"A A"\t"T C whenever there is a 0 0 in any column, the output should be printed as A... (12 Replies)
Discussion started by: rossi
12 Replies

2. Shell Programming and Scripting

sed replacing specific characters and control characters by escaping

sed -e "s// /g" old.txt > new.txt While I do know some control characters need to be escaped, can normal characters also be escaped and still work the same way? Basically I do not know all control characters that have a special meaning, for example, ?, ., % have a meaning and have to be escaped... (11 Replies)
Discussion started by: ijustneeda
11 Replies

3. Shell Programming and Scripting

Replacing Complex Characters in vi

ok, so i have a number of commands like the below in a script: /usr/bin/awk "/ I need to replace the bolded with "^\ but i'm having tremendous difficulties accomplishing this. This needs to be done in vi. can someone please help me out? (4 Replies)
Discussion started by: SkySmart
4 Replies

4. Shell Programming and Scripting

Replacing characters

Hi fellow experts, I have a question for you. Data looks like: 00877,05/13/2010,PBO,P,0000708331,518 00877,05/13/2010,PBO,P,0000708331,519 ... ... 00877,05/13/2010,PBO,P,0000708331,2103 00877,05/13/2010,PBO,P,0000708331,2104,etc,etc Basically I have to replace 518,519,2103,2104,... (4 Replies)
Discussion started by: Devski123
4 Replies

5. Shell Programming and Scripting

Replacing Characters with |

Hi All, example data.log 526569346 66815531961 09 526569346 66815531961 09 526569346 66815531961 09 526569346 66815531961 09 526569346 66815531961 09 I want like this to 526569346|66815531961|09 526569346|66815531961|09... (4 Replies)
Discussion started by: ooilinlove
4 Replies

6. Shell Programming and Scripting

Replacing Characters

Hi All, I have a file which is delimeted with the character '. i need to replace this character with the same character and also a new line. Can anyone please help me with the tr command for this. Many thanks Karan (11 Replies)
Discussion started by: karansachdeva
11 Replies

7. Shell Programming and Scripting

replacing characters

hi all I have a file that has sone spaces in start then / at last. i want to get rid of this. how to do? eg. 11414/ 49878/ 27627/ I WANT THE FILE AS 11414 49878 27627 PLEASE HELP (3 Replies)
Discussion started by: infyanurag
3 Replies

8. UNIX for Dummies Questions & Answers

replacing the characters in a file

hi i want to replace the characters between positions 2 to 30 in each line in a file how to do it suggestions welcome (2 Replies)
Discussion started by: trichyselva
2 Replies

9. UNIX for Dummies Questions & Answers

replacing characters

Hi, I have a script for replacing bad characters in filenames for f in *; do mv $f `echo $f | tr '+' '_'` done; this replaces + for _ But I need to replace all bad characters ? / % + to _ Pls how can i do this in one script ? (3 Replies)
Discussion started by: palmer18
3 Replies

10. Shell Programming and Scripting

how to set a variable to accept alpha-numeric characters?

I am working on a shell program that needs to accept alpha-numeric input (i.e., P00375); when I use a simple 'read' statement to read in the input (i.e., read LOG), I receive the message "p00375: bad number". How must I adjust my input statement to accept alpha-numerics? Thanks! Brent (3 Replies)
Discussion started by: bcaunt
3 Replies
Login or Register to Ask a Question