Remove backquotes from file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove backquotes from file
# 1  
Old 11-24-2011
Remove backquotes from file

Hello,

I have a few thousand files that contain backquotes (`) which were a typo in the program. Now I only want to delete these backquotes from these files.

In these cases I normally use the sed command in a script, but I can't seem to get sed to remove the backquotes. I tried several possibilities:

Code:
sed -i s/\`//g $file

backquote=\`
sed -i s/${backquote}//g $file

and some other things, but all returned the error:

Code:
sed: 1: "/Users/.....": invalid command code B.

I tried to find the explanation for this error, but to no avail. I hope somebody can tell me how to solve this problem.

Thanks,
Björn

Last edited by pludi; 11-24-2011 at 11:18 AM..
# 2  
Old 11-24-2011
Have you tried with single quotes?
Code:
# echo 'somefile with `s' | sed 's/`//g'
somefile with s
# echo 'somefile with `s' | tr -d '`'
somefile with s

# 3  
Old 11-24-2011
perl:
Quote:
perl -pi -e 's/'\`'//g' file
This User Gave Thanks to kevintse For This Post:
# 4  
Old 11-24-2011
CarloM, the command you posted works onscreen, but it does not alter the file itself. I need it to change it in the file itself, therefore I use the -i flag, but when doing that, it gives an error again. This time it's

Code:
invalid command code E

Any other suggestions?

---------- Post updated at 10:35 AM ---------- Previous update was at 10:32 AM ----------

Ooh, just saw kevintse's reply, and that works! Thanks man!
# 5  
Old 11-24-2011
It works for me! Smilie
Code:
# x.txt
somefile with `s
# sed -i 's/`//g' x.txt
# cat x.txt
somefile with s

(GNU sed 4.1.5)

If neither that or kevintse's code works for you then an alternative might be to write a shell script wrapper to use a temporary file.
# 6  
Old 12-06-2011
with awk
Code:
echo 'testing`s' | awk -v a='`' '{gsub(a,"")}1'


Last edited by Franklin52; 12-07-2011 at 03:25 AM.. Reason: Please use code tags for code and data samples, thank you
# 7  
Old 12-07-2011
Go with tr too ..
Code:
$ tr -ds '`' '' < infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Remove lines from File.A based on criteria in File.B

Hello, I have two files of the following form. I would like to remove from File.A where the first three colum matches values in File.B to give the output in File.C File.A 121 54321 PQR CAT 122 765431 ABC DOG 124 98765 ZXY TIGER 125 86432 GEF LION File.B 122 765431 ABC 125 86432 GEF... (4 Replies)
Discussion started by: Gussifinknottle
4 Replies

2. Shell Programming and Scripting

awk remove/grab lines from file with pattern from other file

Sorry for the weird title but i have the following problem. We have several files which have between 10000 and about 500000 lines in them. From these files we want to remove lines which contain a pattern which is located in another file (around 20000 lines, all EAN codes). We also want to get... (28 Replies)
Discussion started by: SDohmen
28 Replies

3. Shell Programming and Scripting

ksh Loop through file one, remove lines from file two

Good Afternoon, I start with a file named biglist.txt. I have another file smallerlist. txt I want to remove the lines from smallerlist.txt from biglist.txt and leave those lines that do not reside in smallerlist.txt. Thanks !! (2 Replies)
Discussion started by: popeye
2 Replies

4. Shell Programming and Scripting

Remove comments from file with specific file name extensions

Hello Unix board community, I have to program a shell script, but I am a complete noob so I hope I get some help here. The assignment is as follows: The program removes all comments regardless of formatting or language from files with specific file name extensions (php, css, js, ...).... (3 Replies)
Discussion started by: TheZeusMan
3 Replies

5. Shell Programming and Scripting

Remove bad records from file and move them into a file then send those via email

Hi my requirement is that i want pull the bad records from input file and move those records in to a seperate file. that file has to be sent via email.. any suggentions please (1 Reply)
Discussion started by: sxk4999
1 Replies

6. Shell Programming and Scripting

Remove the file content based on the Header of the file

Hi All, I want to remove the content based on the header information . Please find the example below. File1.txt Name|Last|First|Location|DepId|Depname|DepLoc naga|rr|tion|hyd|1|wer|opr Nava|ra|tin|gen|2|wera|opra I have to search for the DepId and remove the data from the... (5 Replies)
Discussion started by: i150371485
5 Replies

7. Shell Programming and Scripting

need to remove 1st line of a file and save the file with same old name

Hi friends, I have a doubt, I am not sure whether it is possible ah nu. I am having a file(sample.txt) which contain 5 lines. I want to remove 1st line in the file and save the file with same old name (sample.txt). For removing 1st line i am using sed 1d filename But dono how to... (3 Replies)
Discussion started by: natraj005
3 Replies

8. UNIX for Dummies Questions & Answers

how to copy a file without remove the contents of the target file?

Hello every body, Kindly support me to "copy a file without remove the contents of the target file" Thanks in advance. :) Ahmed Amer Cairo,Egypt (2 Replies)
Discussion started by: ahmedamer12
2 Replies

9. Shell Programming and Scripting

Batch file to remove double quotes from a file

Hi I have to create a windows batch file which will read an input file and remove "double quotes" from each line of the file. For eg.If input file name is abcd.csv and contents is : "asasd,123123,213213,asd" "esfrf,dsfsdf,234324,sdfsdf" Then the batch file should remove "" from the... (11 Replies)
Discussion started by: akashtcs
11 Replies

10. UNIX for Dummies Questions & Answers

awk field not recognized in backquotes

Hi, I am writing a script to use awk to generate a set of cp commands from an input file abc. file abc: /data/a.dbf /data/june/b.dbf desired output: cp -pr a.dbf /data/a.dbf cp -pr b.dbf /data/june/b.dbf script: $ cat abc | awk '{ print "cp -pr '`basename $1`' " $1 }' I tried to... (4 Replies)
Discussion started by: voa2mp3
4 Replies
Login or Register to Ask a Question