I think you're misunderstanding what I'm trying to do.
Perhaps.
Your attempt to wrap everything in single quotes suggests that you would like to pass the arguments verbatim. If that is indeed the case, the sed is too late; pathanme expansion will have already occurred.
Assuming that the current directory has two files, f1 and f2, if you have a line in the file with cmd *, should cmd's first positional parameter be set to *, or should the single * argument expand to two positional parameters, f1 f2? If when invoked cmd should see a literal *, the sed is too late unless globbing is disabled (same goes for other pathname expasnion metacharacters in my example, ?, [...]) because the parsing of the set -A statement will have already expanded the pathnames after it expands $line (since $line must undergo field splitting to yield multiple members for the array, the usual way to prevent pathname expansion, double quoting, cannot be used). So instead of yielding '*', the quoting step will yield 'f1' 'f2'.
For escaping the single quotes and single quoting each word in a line:
Regards,
Alister
---------- Post updated at 03:26 PM ---------- Previous update was at 03:17 PM ----------
Quote:
Originally Posted by aaron0001
awk is obviously a swiss army knife. But at this point I would like to know why I can't accomplish a replace of ' with ''\' with sed.
With ksh93, a couple of parameter expansion and assignment operations can also accomplish the task:
Note that this does not sidestep the possible issue of pathname expansion during the set statement.
Regards,
Alister
---------- Post updated at 04:08 PM ---------- Previous update was at 04:04 PM ----------
Quote:
Originally Posted by aaron0001
However we must be in different shells / environments because my environment works differently than yours.
For example:
That's typical POSIX-compliant pathname expansion behavior. Given identical commands, my shell would produce identical output.
I believe you may have missed my point regarding pathname expansion.
I think we are still speaking different languages. Your first few sentences agree with me while saying you don' agree =/.
Did you check the program I posted which precisely matched your requested output?
Scratch that, I understand your point.
It's not just a different language though, I'm using a totally different logic, which could apply just as well to sed as awk.
Why bother splitting it into arguments before you've substituted for special chars? Why bother reading it into the shell, splitting, feeding it into sed piece by individual piece, getting it back out, etc, etc, etc when a single use of sed can escape the entire file in one whack and save you all the complication of dealing with the shell's own substitution and read's own escaping. It also means less chance of errors -- you don't need to armor-plate a substitution that you don't need to feed into sed in the first place. That's also way more efficient.
Last edited by Corona688; 03-02-2012 at 05:26 PM..
Hi.
I 'm trying to hit a REST api and retrieve a JSON feed, and the URL has special characters in it.
Something like:
Example Domain
The below curl command is failing
curl -X GET https://www.example.com/?sample=name&id=1001
saying bad command at id=1001
I am going to use this as part... (3 Replies)
Hi,
I am using sed command to replace following line in gz file-
sed -n 's/""COS_12_TM_1" ( 1101110101001001010011110100000010110100010010000000100000000010XX010000000 )"/""COS_12_TM_1" ( 110111010100100101001111MM00000010110100010010000000100000000010XX010000000 )"/g' filename.gz
$x=... (4 Replies)
I have an application which I am integrating with that accepts the password via a CLI. I am running in to issues with passwords that contain special characters. I tried to escape them all, but I ran in to an issue where I cannot escape the characters
'
]
My attempt is as follows:
$... (2 Replies)
Hi
I have a scenario where hyphen(-) from file should be ignored
I used the following code
if && ; then
if ; then
pow=$LINE
echo $pow > history.txt
flag=1
fi
fi
I get the following output
./valid.sh: -: 0403-012 A test... (7 Replies)
I am writing a ksh script. I need to replace a set of characters in an xml file.
FROM="ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÛÚÜÝßàáâãäåçèéêëìíîïðñòóôõö¿¶ø®";
TO="AAAAAAACEEEEIIIIDNOOOOOOUUUUYSaaaaaaceeeeiiiionooooo N R"
I have used the code- sed 's/$FROM/$TO/g'<abc.xml
But its not working.
Can anyone tell me the code to do this? (3 Replies)
i need to replace the any special characters with escape characters like below.
test!=123-> test\!\=123
!@#$%^&*()-= to be replaced by
\!\@\#\$\%\^\&\*\(\)\-\= (8 Replies)
Hi all,
I was wondering how can i see the special characters like \t, \n or anything else in a file by using Nano or any other linux command like less, more etc (6 Replies)
When I open a file in vi, I see the following characters:
\302\240
Can someone explain what these characters mean. Is it ASCII format? I need to trim those characters from a file.
I am doing the following:
tr -d '\302\240'
---------- Post updated at 08:35 PM ---------- Previous... (1 Reply)