Sed Replace a repeating character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sed Replace a repeating character
# 1  
Old 06-23-2009
Sed Replace a repeating character

I have a text file and every line ends in

Code:
|^
|^^
|^^^
|^^^^

I need to use sed to make all lines end it

Code:
|^

regardless of the amount of carrots.

The code i was using is:

Code:
cat FILE | sed 's/\^\^\^/\^/g'

But then they threw that curveball at me. Also is there a way to remove the newline after the |^

Thanks,

Sean
# 2  
Old 06-23-2009
Code:
sed 's/|^^*$/|^/' myFile


Last edited by vgersh99; 06-23-2009 at 06:13 PM.. Reason: 1 or more ^ - added a '^'
# 3  
Old 06-23-2009
using Perl:
Code:
perl -pi -e 's/\^+$/^/' file.txt

and if you want to remove newlines also:
Code:
perl -pi -e 's/\^+$/^/;  chomp;' file.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed Character match and replace

Hello All I am struck in the issue which I want to share with all of you. What I am trying to do is For every line in a file I have to replace a particular character from the given character in a file For Example Suppose the data is 1111x2222 1111x2222 2222y3333 1111x2222 I... (4 Replies)
Discussion started by: adisky123
4 Replies

2. Shell Programming and Scripting

Sed replace using same pattern repeating multiple times in a line

Sed replace using same pattern repeating multiple times in a line I have text like below in a file: I am trying to replace the above line to following How can I acheive this? I am able to do it if the occurrence is for 1 time: But If I try like below I am getting like this: I have to... (4 Replies)
Discussion started by: sol_nov
4 Replies

3. Shell Programming and Scripting

How to replace special character using sed?

How can I replace the follong text including to number 7000? cat tmp0.txt Winston (UK) Wong I would the 7000 to replace Winston (UK) Wong. I fail with method below: sed ' s /Winston\(UK\)Wong/7000 tmp0.txt' (1 Reply)
Discussion started by: vivien_chu
1 Replies

4. Shell Programming and Scripting

sed command to replace a character at last

Hi All, I have a file having one line only. It is like trapsess:inform|10.232.167.18|1|1|50|25|0|0|0|5|1|1|78|0037| I want to replace the numbers in last two columns by As. It should look like trapsess:inform|10.232.167.18|1|1|50|25|0|0|0|5|1|1|AA|AAAA| Please, suggest me any shell... (12 Replies)
Discussion started by: mukeshbaranwal
12 Replies

5. Shell Programming and Scripting

how to replace the special character with another using SED

I have the replace the pattern in the file , ); to ); Could someone please help me to get this command. (2 Replies)
Discussion started by: mohan.bit
2 Replies

6. Shell Programming and Scripting

sed special character replace

I need to do the following: text in the format of: ADDRESS=abcd123:1111 - abcd123:1111 is different on every system. replace with: ADDRESS=localhost:2222 sed 's/ADDRESS=<What do I use here?>/ADDRESS=localhost:2222/g' Everything I've tried ends up with: ... (3 Replies)
Discussion started by: toor13
3 Replies

7. Shell Programming and Scripting

In Sed how can I replace starting from the 7th character to the 15th character.

Hi All, Was wondering how I can do the following.... I have a String as follows "ACCTRL000005022RRWDKKEEDKDD...." This string can be in a file called tail.out or in a Variable called $VAR2 Now I have another variable called $VAR1="000004785" (9 bytes long), I need the content of... (5 Replies)
Discussion started by: mohullah
5 Replies

8. Shell Programming and Scripting

sed help,to replace the last character

cat input.txt agsbdafgd ertebrtreter ahrbrwerg The last character of a line that does not start with a would be changed to Z. Final output: agsbdafgd ertebrtreteZ ahrbrwerg Can anyone post the sed command to do that? (2 Replies)
Discussion started by: cola
2 Replies

9. Shell Programming and Scripting

Sed Replace repeating pattern

Hi, I have an sqlplus output file using the character ';' as a delimiter and I would like to replace the fields without datas (i.e delimited by ';;') by ';0;' Example: my sqlplus output: 11;22;33;44;;;77;; What I would like to have: 11;22;33;44;0;0;77;0; Thanks in advance for your... (2 Replies)
Discussion started by: popesk
2 Replies

10. Shell Programming and Scripting

replace first character of string sed

I want to change the first/or any character of a string to upper-case: String: test Desired results: Test or tEst or teSt or tesT thanks (6 Replies)
Discussion started by: prkfriryce
6 Replies
Login or Register to Ask a Question