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 - optional brackets
ICU Regex matching for non-digit and no whitespace
Seemingly incorrect regex evaluation in regexp_replace
How to detect a string which does not include " using flex?
Extract certain values from string in .txt files with PowerShell
Apache 301 Redirect Add language prefix if not present
Regex, match characters and doesn't contain more than one _ followed by another _
Regex ignore word
Regex not valid in google sheets error?
extract substring using regex in shell script
Eclipse Add text to first line of all files
Renaming files by using a prefix from text file
Python regex to find words, which also excludes particular words
Regex - exclude search results
Update a line in the AD info field
Sed Match Number followed by string and return Number

Categories

HOME
amazon-s3
uwp
dicom
copy
varnish
haskell-stack
azure-web-sites
stripe-payments
r-caret
tcplistener
wso2ei
google-weather-api
numericupdown
android-dialogfragment
eigen3
nsmutableattributedstring
spring-restdocs
nxbre
accelerated-mobile-page
c-strings
csom
py4j
background-subtraction
naturallyspeaking
mediacodec
webfocus
valueinjecter
true-type-fonts
kubernetes-go-client
blockui
gridstack
sieve-of-eratosthenes
argparse
powerbuilder-conversion
paypal-rest-sdk
projection
project-centennial
nscalendar
strip-tags
http-status-code-500
manifoldjs
website-hosting
recurrence
complement
glfw
mspgcc
abbyy
fasta
android-identifiers
view-source
itertools
findall
waf
informatica-cloud
tfs2008
redux-framework
ota
pakyow
storage-duration
sqlj
genetic
aldryn
ironmq
user-registration
nbug
iphone-5
stringr
odoo
spiceworks
misra
cvs2git
publish-actions
controlsfx
pkcs#10
email-spam
serverside-javascript
ituneslibrary
xsltforms
fay
showcaseview
re2c
llblgenpro
ioerror
firebird2.1
argumentexception
12factor
gigaspaces
jcycle
arden-syntax
cellid
hpple
c++builder-xe2
semantic-zoom
ondraw
gemstone
xmltextwriter
paredit
syncml
symstore
remote-control
custom-protocol
scramble
network-scan

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