Removing a character using sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing a character using sed
# 1  
Old 01-23-2007
Removing a character using sed

Hi,

I have a file with the text below. How do i remove the character "%" from the text file using sed ? Can anybody help ?

0%
68%
72%
0%
54%
33%
75%
24%
6%
59%
77%
77%
33%
# 2  
Old 01-23-2007
Code:
sed 's/%//' file > newfile

# 3  
Old 01-23-2007
basically, its just something like this
Code:
echo "68%" | sed "s/%$//" #assume % is always at the end.

# 4  
Old 01-23-2007
You guys are great! It works !Thanks a million
# 5  
Old 09-17-2007
What if you could possibly have more than one % character at the end of the string? What command would you use then to ensure that there were no % chars at the end?

I ask b/c I want to take a directory path that a user passes me, and if there are any / chars at the end, I want to delete them all.


thanks to all for any help...
# 6  
Old 09-17-2007
Quote:
What if you could possibly have more than one % character at the end of the string? What command would you use then to ensure that there were no % chars at the end?
Code:
echo "82%%%" | sed 's/%*$//'

Quote:
I ask b/c I want to take a directory path that a user passes me, and if there are any / chars at the end, I want to delete them all.
Code:
echo "/this/is/my/path////" | sed 's!/*$!!'

# 7  
Old 11-21-2008
remove string contains /

How can remove string contains / in a file
for example my input like
Code:
<dgjfgjdgfjsdg/kdfhgdhgjkhdfjkg/jkdfjhdk/kjfdhgkdjh=kjfh:"dfjgdjfg"><dfjvgdjgvdjgfvjdgfjgdjfgjkdg><jdfgvjdgfjgbdjfgbj>

i would like to remove

Code:
<dgjfgjdgfjsdg/kdfhgdhgjkhdfjkg/jkdfjhdk/kjfdhgkdjh=kjfh:"dfjgdjfg">


Last edited by jim mcnamara; 02-11-2016 at 12:43 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed searches a character string for a specified delimiter character, and returns a leading or traili

Hi, Anyone can help using SED searches a character string for a specified delimiter character, and returns a leading or trailing space/blank. Text file : "1"|"ExternalClassDEA519CF5"|"Art1" "2"|"ExternalClass563EA516C"|"Art3" "3"|"ExternalClass305ED16B8"|"Art9" ... ... ... (2 Replies)
Discussion started by: fspalero
2 Replies

2. Shell Programming and Scripting

sed removing extra character from end

Hi, Searching through forum I found "sed 's/*$//'" can be used to remove trailing whitespaces and tabs from file. The command works fine but I see minor issue as below. Can you please suggest if I am doing something wrong here. $ cat a.txt upg_prod_test upg_prod_new $ cat a.txt |sed... (11 Replies)
Discussion started by: bhupinder08
11 Replies

3. Shell Programming and Scripting

removing last character

Hi, I have a file that has data something like below: A B C D ..... ...... .....and so on I am trying to bring it in one line with comma delimited something like below : A,B,C,D I tried the something below in the code section: cat File.txt | tr '\n' ',' (1 Reply)
Discussion started by: rkumar28
1 Replies

4. UNIX for Dummies Questions & Answers

Need help removing last character of every line if certain character

I need help removing the last character of every line if it is a certain character. For example I need to get rid of a % character if it is in the last position. Input: aaa% %bbb ccc d%dd% Output should be: aaa %bbb ccc d%dd I tried this but it gets rid of all of the % characters.... (5 Replies)
Discussion started by: raptor25
5 Replies

5. UNIX for Dummies Questions & Answers

Removing a character

I need to remove square brackets from output of script. Output is: and I need to remove the square brackets so I am lett with 121 Is sed the only means to do this and if so what are the options? ...ok so far I have managed to get rid of ] by using /usr/bin/sed 's/]//' but that... (5 Replies)
Discussion started by: rob171171
5 Replies

6. Shell Programming and Scripting

Need some help removing a character from name

I have a file like this: DDD_ABCDE2AB2_1104081408.104480 I need to remove the 1 after the . in the file name so that it reads: DDD_ABCDE2AB2_1104081408.04480 Having some difficulty getting the command to work. I tried using cut -d 26 but that just doesn't work. (3 Replies)
Discussion started by: bbbngowc
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

removing the "\" and "\n" character using sed or tr

Hi All, I'm trying to write a ksh script to parse a file. When the "\" character is encountered, it should be removed and the next line should be concatenated with the current line. For example... this is a test line #1\ should be concatenated with line #2\ and line number 3 when this... (3 Replies)
Discussion started by: newbie_coder
3 Replies

9. Shell Programming and Scripting

Removing '." character using SED

HI All, Have some files which contains some string like, "create .<table1> as" "insert into .<table2> values", i want to replace ".<table1>" with only "<table1>", i.e removing '.' character in ksh, i have written below code but it is not removing the dot character, any help? for name... (2 Replies)
Discussion started by: arvindcgi
2 Replies

10. UNIX for Dummies Questions & Answers

Removing the ^M character in VI

Hello, I am attempting to remove all the ^M characters in a file in VI. The command I am using is :1,$s/^V^M//g but it doesn't work, saying 'substitute pattern match failed'. Any ideas why? Jules (2 Replies)
Discussion started by: julesinbath
2 Replies
Login or Register to Ask a Question