regex


add quotes to words matching regex in file awk or sed


I want to add quotes to words in file matching particular regex using any tool, maybe vi, awk or sed. File contain many lines like this.
take this line for example::
'SellerName',2013-08-20 17:19:49,71.185.24.60,-8523106007192903367,5526150741,1,null,25d20a500342-653AC57AF9E6401B,16,2574455867,product description,-8574103407192903368,353860,_,null,-1
I would like to put single quotes around IP (71.185.24.60) and around the session id (25d20a500342-653AC57AF9E6401B).
I looked into awk, sed and vi but could not find how to insert matched-patterns in the substitution.
Let me know if you have some way to do it.
This is pretty straightforward with awk:
awk '{ $3 = q $3 q; $8 = q $8 q } 1' FS=, OFS=, q=\' infile
This tells awk that the input and output are comma separated (FS=, OFS=,) and assumes that none of the fields contain embedded commas. Field 3 and 8 receive quotes through the q variable.
Output:
'SellerName',2013-08-20 17:19:49,'71.185.24.60',-8523106007192903367,5526150741,1,null,'25d20a500342-653AC57AF9E6401B',16,2574455867,product description,-8574103407192903368,353860,_,null,-1
sed -i s/71.185.24.60/"'71.185.24.60'"/g filename
Similarly for the other pattern.

Related Links

Regular Expressions match exactly 7 or 9 digits
How to accept numbers and specific words?
Javacc regular expression that matches all string except certain ones
perl regex - extract words between 2 separators
Regex number extraction
How to delete slash from the str?
how to use regex to strip the preprocessor directive
Find a string in multiple files using grep
Regex find and replace over multi lines in Shell
Grepping a 20g file in bash
What Perl matching regexp nuances can cause headaches?
What is the invalid URI error from SpamAssassin actually matching?
Validate postal cade using Regex on each character
VBA regex - match an expression that doesn't begin with a particular word
How to pass variable to regular expression in PERL
Batch rename screen shots on Mac OS X

Categories

HOME
selenium
configuration
prebuild
middleware
turing
android-sms
windows-server-2012-r2
predictionio
ceph
apache-spark-sql
windows-10-desktop
push
identifier
tapi
yii2-advanced-app
reload
lighttpd
html5-video
group-by
cloudrail
contains
similarity
jet
shape
hawq
spring-batch-admin
toolbar
simple-html-dom
android-arrayadapter
plm
debugview
file-manager
dokuwiki
vrtk
spring-websocket
nio
joe-editor
otroslogviewer
runc
bem
mindstorms
mamp-pro
mdanalysis
monogame
log4perl
sections
arm7
jquery-masonry
tpl-dataflow
kony
paypal-webhooks
ice
waf
asp.net-mvc-custom-filter
bootstrap-slider
xmllint
vb6-migration
uploadify
webpack-hmr
blpapi
highslide
lidar
filenet-content-engine
sejda
post-processor
phone-number
cvc4
pegkit
structured-programming
alienvault
pencilblue
alt
declaration
dynamic-data-display
eventmachine
team-explorer-everywhere
asp.net-apicontroller
xml.modify
jquery-mobile-popup
jquery-data
impdp
layout-manager
alternate-data-stream
wescheme
guvnor
ad-hoc-distribution
arr
proxy-classes
websolr
project-settings
clipboard-pictures
sqlprofileprovider
reference-library

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App