awk with sed?
awk with sed?
(OP)
Suppose I have this line
Subject: Don't play with fire
and I want to remove the ' character (our database doesn't like it), could this be done by somehow combining
sed 's/'//g'
with awk /^Subject/ {$0=" can I put sed here? "}
or is there an easier way?
Subject: Don't play with fire
and I want to remove the ' character (our database doesn't like it), could this be done by somehow combining
sed 's/'//g'
with awk /^Subject/ {$0=" can I put sed here? "}
or is there an easier way?
RE: awk with sed?
Sure is possible. At least with GNU Awk. However it is abit lengthy because the two way communication :
CODE --> ask-sed-to-remove-single-quote.awk
CODE --> command line
master # gawk -f ask-sed-to-remove-single-quote.awk <<< "Subject: Don't play with fire" BEFORE Subject: Don't play with fire AFTER Subject: Dont play with fire
Or with any standard compliant Awk :
CODE --> Awk
But I strongly recommend to never do that - never alter the data just to satisfy the storage or transport layer.
What kind of database is that ? For SQL databases ( and most of the NoSQL databases too ) you must escape text data. Escaping may depend on the database type and internal encoding and beside the string delimiters may require the escaping of the escape character too. For this reason, escaping solutions are provided for most of the databases/drivers/libraries.
So better give use details on your database and the intended use.
Feherke.
feherke.ga
RE: awk with sed?
The gsub was all I needed - many thanks for pointing me in the right direction.
I agree with you that this is not the proper way to go about the issue, but it is a quick and dirty solution that will work until they get their database issues resolved