INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

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?

RE: awk with sed?

Hi

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

{
    print "BEFORE", $0

    p = "sed \"s/'//\""

    print |& p
    close(p, "to")

    p |& getline
    close(p, "from")

    print "AFTER ", $0
} 

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

gsub(/'/, "") 

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?

(OP)
Sorry for the late reply...
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 smile

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close