Sponsored Content
Top Forums UNIX for Dummies Questions & Answers How to replace special chars like " ' " (Apostrophe) Post 302251354 by dan-e on Sunday 26th of October 2008 09:45:33 PM
Old 10-26-2008
.... haha I'm only reading this forum so that I can learn more myself, but I came across a similar example in a hardcopy book called "Sed & Awk" (O'reilly). According to the book you don't need to enclose your sed argument with quotes (as you have in this example - single quotes), and I'm sure this is what was breaking your statement.

I tried a few things myself and decided it was the outside quotes breaking things, and then found out you can enclose your pattern and substitution string with double quotes (not sure if singles work too). Gave it a shot and it worked.

The reason that your example fails is because these such commands rely on 'delimeter' characters to break up their data. Eg. for a program to read a string it finds the next quote - " - and then starts grabbing anything after the quote until it hits another quote - " - and then says 'everything in-between is the string'. Of course this doesn't work if the string itself contains a quote, like in your example. To get around this problem, they invented 'escape' characters which say to the program 'hey don't worry about this quote - it's part of the string' Eg:
1. "A string" = A string
2. "A string with \"escape characters\"" = A string with "escape characters"
3. "A broken string without "escape characters"" = A broken string without

Your example falls into category 3. However, I couldn't find a way to use an escape character with the single-quote. I would have thought that this would work:

Code:
sed 's/\'/ /g' aaa.txt >zzz.txt

- Note the \ escape character preceding the single-quote. But this doesn't work. I don't know why, if people would program like me it would work. Smilie But they don't. Which is why bad software exists. And microsoft.

Last edited by dan-e; 10-26-2008 at 10:46 PM.. Reason: Fixed ugliness
 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing " " chars using Awk

HI Friends, I am trying to elliminate the " " characters from the word: "hello" using awk. I need the output to be just = hello (without " " chars). Is there any way to do this ? Thanks! (3 Replies)
Discussion started by: vijaya2006
3 Replies

2. Shell Programming and Scripting

Question about special variables: "-" and "$_"

both ksh/bash support this 2 special variables, Is there any document for reference? 1) "-" is $OLDPWD 2) "$_" is last argument of previous command. (4 Replies)
Discussion started by: honglus
4 Replies

3. Shell Programming and Scripting

How to replace "®" "™" "with Spaces in UNIX

do U know how to replace the registered trademark "®" symbol or trade Mark "™" "with Spaces in UNIX (4 Replies)
Discussion started by: MMeari
4 Replies

4. Shell Programming and Scripting

Delete chars after dot "."

Hi, I require to delete all characters after a dot "." from a string. For e.g. input_var="/home/dips/file_1_20100726.txt.gz /home/dips/file_2_20100726.txt.gz /home/dips/file_3_20100726.txt.gz" output_var="/home/dips/file_1_20100726 /home/dips/file_2_20100726... (3 Replies)
Discussion started by: dips_ag
3 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. UNIX for Dummies Questions & Answers

replace "," with "." only in specific columns of a file?

Hi all, I have this text file containing 9 columns separated by space. The 8th columns contains the numbers. C1 C2 C3 C4 C5 C6 C7 C8 C9 er rt yt gh iu nk il 0.07 xs yt lr ty bg iu zk nh 0,0005 lt ...etc. I want to replace the comma with full stop only in 8th coloumn. the output... (8 Replies)
Discussion started by: Unilearn
8 Replies

7. Shell Programming and Scripting

"set variable with spaces and apostrophe after s"

Hi Guys, I have a variable such that: set x = (Session,Date,Type,Receive Coil Name,Manufacturer,Manufacturer's Model Name) foreach i ($x) echo $i end I would like to read each variable one by one like: Session Date Type Receive Coil Name Manufacturer Manufacturer's Model Name Is... (1 Reply)
Discussion started by: dixits
1 Replies

8. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies
LESSECHO(1)						      General Commands Manual						       LESSECHO(1)

NAME
lessecho - expand metacharacters SYNOPSIS
lessecho [-ox] [-cx] [-pn] [-dn] [-mx] [-nn] [-ex] [-a] file ... DESCRIPTION
lessecho is a program that simply echos its arguments on standard output. But any metacharacter in the output is preceded by an "escape" character, which by default is a backslash. OPTIONS
A summary of options is included below. -ex Specifies "x", rather than backslash, to be the escape char for metachars. If x is "-", no escape char is used and arguments con- taining metachars are surrounded by quotes instead. -ox Specifies "x", rather than double-quote, to be the open quote character, which is used if the -e- option is specified. -cx Specifies "x" to be the close quote character. -pn Specifies "n" to be the open quote character, as an integer. -dn Specifies "n" to be the close quote character, as an integer. -mx Specifies "x" to be a metachar. By default, no characters are considered metachars. -nn Specifies "n" to be a metachar, as an integer. -fn Specifies "n" to be the escape char for metachars, as an integer. -a Specifies that all arguments are to be quoted. The default is that only arguments containing metacharacters are quoted SEE ALSO
less(1) AUTHOR
This manual page was written by Thomas Schoepf <schoepf@debian.org>, for the Debian GNU/Linux system (but may be used by others). Send bug reports or comments to bug-less@gnu.org. Version 458: 04 Apr 2013 LESSECHO(1)
All times are GMT -4. The time now is 09:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy