Replace backslash at the end of the string using sed command

Thread Tools Search this Thread
# 1  
Replace backslash at the end of the string using sed command

I have text file which is a tab delimited one. Sample data from the file is shown below:

unix    is\    great\    os
linux\   is    superb

I want to replace that backslash with empty string preserving the tab delimiter. Output should be

unix    is    great    os
linux   is    superb

Please help me in solving this using sed command.

---------- Post updated at 11:38 PM ---------- Previous update was at 11:37 PM ----------

If the backslash character is in the middle of the string, i dont want to replace that one in the string.
# 2  

sed 's/\\\t/\t/g' file

This User Gave Thanks to guruprasadpr For This Post:
# 3  
Thanks for the quick reply..Its working fine.
# 4  
perl -pe 's/(?<=\w)\\(?=\s)//g' file


Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue with sed command does not replace exact string matched

I have a file change.sed more change.sed I fire the below command inorder to replace "" with "" in proxy.logsed -f change.sed proxy.log proxy.log has the below entry more proxy.log The command replaces both & as below: I am expecting... (17 Replies)
Discussion started by: mohtashims
17 Replies

2. Shell Programming and Scripting

How to search and replace string in column in file with command sed?

how to search and replace string in column in file with command sed or other search "" and replace column 4 = "W" $ cat file.txt|20150120|Y|N|N|20150120|Y|N|N|20150120|Y|N|N|20150120|Y|N|Noutput... (4 Replies)
Discussion started by: ppmanja3
4 Replies

3. Shell Programming and Scripting

sed command to replace string that contain blackslash,double quotes

Hi All, I have been trying to replace a string using the sed command string value contain blackslash and double quotes. I am not a expert writer of unix script but do try not to ask question. I have almost given up. Hope you all can give me some suggestion I want to replace a place string... (6 Replies)
Discussion started by: thanush9sep
6 Replies

4. Shell Programming and Scripting

Replace string and append Indicator to end of record in Linux

Hi All, Could you please help me to achieve below solution. I have a FILE1.txt as below.TEXAS CALIFORNIA TEXAS DALLAS CALIFORNIA CALIFORNIA DALLAS DALLAS TEXAS TEXAS DALLAS NEW YORK NEW YORk FILE2.txt as below.TEXAS,TX DALLAS,DA Now I need to compare the string in FILE2.txt... (6 Replies)
Discussion started by: ureddy
6 Replies

5. Shell Programming and Scripting

Help with Passing the Output of grep to sed command - to find and replace a string in a file.

I have a file example.txt as follows :SomeTextGoesHere $$TODAY_DT=20140818 $$TODAY_DT=20140818 $$TODAY_DT=20140818I need to automatically update the date (20140818) in the above file, by getting the new date as argument, using a shell script. (It would even be better if I could pass... (5 Replies)
Discussion started by: SriRamKrish
5 Replies

6. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

7. Shell Programming and Scripting

simple sed question - replace from phrase to end of line

I have the following line an in input file I want to digest with sed and simple replace the bold part with a variable defined in my bash script. I can do this in several sed operations but I know there must be a way to do it in a single sed line. What is the syntax? Line in file:... (1 Reply)
Discussion started by: graysky
1 Replies

8. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

9. Shell Programming and Scripting

Cut on last backslash on hyperlink string-sed/awk??

hyper link- abc:8081/xyz/2.5.6/rtyp-2.5.6.jar Needs to get "rtyp-2.5.6.jar" i.e character after last backslash "/" how to do this using sed/awk?? help is highly appreciated. (7 Replies)
Discussion started by: kkscm
7 Replies

10. Shell Programming and Scripting

sed : replace space and end-of-line

Hi ! I'm rather new with sed ... learned a lot already by googling etc ... The following script should replace all spaces and ends-of-lines with "something (see below). #!/bin/bash i=0 while read line do fam="H`printf "%06d" $i`" echo $line | sed -e 's//\t'$fam'\n/g' i=$(($i+1))... (7 Replies)
Discussion started by: jossojjos
7 Replies

Featured Tech Videos