regex


Sed. Blank a field in csv file that includes symbol


I have a large .csv file that looks like this:
ABC, 10, <10.0, 10.0, ABC
ABC, < 0.9, 10, 10.0, ABC
I need to remove the fields that contain "<". Sometimes it's just "<" and numbers, sometimes it contains spaces, and it can appear on any column. This is the output I'm looking for:
ABC, 10, , 10.0, ABC
ABC, , 10, 10.0, ABC
The closest thing to a success I got was
grep -oP '(?<=,)(<.*?)(?=,)' text.csv
printed
<10.0
< 0.9
which is what I want to delete. But
sed -i 's/(?<=,)(<.*?)(?=,)/ /g' text.csv
does not work.
I ask for a sed solution because I'm a little familiar with it. But all suggestions are welcome. Thanks!
Using sed:
sed 's/[^,]*<[^,]*//g' file
Using awk
awk '{for (i=1;i<=NF;i++) if ($i~/</) $i=""}1' FS=, OFS=, file
ABC, 10,, 10.0, ABC
ABC,, 10, 10.0, ABC
this awk one-liner works, and more straightforward than sed.
awk -F, -v OFS="," '{for(i=1;i<=NF;i++)if($i~/</)$i=""}7' file
test
kent$ echo "ABC, 10, <10.0, 10.0, ABC
ABC, < 0.9, 10, 10.0, ABC"|awk -F, -v OFS="," '{for(i=1;i<=NF;i++)if($i~/</)$i=""}7'
ABC, 10,, 10.0, ABC
ABC,, 10, 10.0, ABC
Using sed as requested.
sed 's/[ ]*<[^,]*//g'
This awk should do:
awk '{gsub(/ ?< ?[^,]*/,x)}8' text.csv
ABC, 10,, 10.0, ABC
ABC,, 10, 10.0, ABC

Related Links

Creating Index based on another field in logstash
Bug in R's grepl? [closed]
Regular Expression Google Form only numbers in a range
MS Word VBA macro to search and replace (Regex)
Repeat capture group ignoring whitespaces
regex help in notepad++ marking embedded values and copying into a new list
uWSGI routing rule is overriding static files
How to match more than one pattern and delete a line using sed?
move pattern in file over one column if match awk
Printing out sentences on separate lines using textOutput() in Shiny
Python: Count items, store count as variable, for statement with string replace to number items in external file
Perl - Using regex to match input in hash key or value
Should I use AWK or SED to remove commas between quotation marks from a CSV file? (BASH)
Reversing a string in perl without using “reverse” function
RegEx / Regular expression for european dates (“j. F Y”)
Need help finding specific folders

Categories

HOME
elf
spring-roo
anylogic
stack
prometheus
tsql
jbpm
copy-paste
wavelet
command-line-arguments
cloudrail
nsmutableattributedstring
jscodeshift
windows-applications
ormlite-servicestack
sencha-touch-2
google-distancematrix-api
csom
intersystems
grouping
android-button
phonegap-desktop-app
valueinjecter
capstone
nib
azure-app-service-envrmnt
p4-lang
qweb
mindstorms
hawkular
nexus-5
angularjs-routing
botkit
program-slicing
default-browser
jquery-masonry
xbrl
ios-app-group
node.js-tape
attributerouting
gpt
iseries-navigator
geneticsharp
turbo-c
measurement-protocol
flattr
webtrends
pager
groups
oracle-policy-automation
accounts
okuma
flexigrid
egl
multer
crosswalk
hypervisor
translucency
wss4j
gem
google-swiffy
theorem-proving
min3d
servlet-listeners
boxapiv2
android-menu
asf
iphone-privateapi
serverside-javascript
validform
windows-phone-7.1
tlb
vlfeat
llblgenpro
resolver
apache-commons-dbcp
couchpotato
12factor
pixelsense
applaud
mysql-backup
quilt
openid4java
f2c
jammit
ramaze
openfeint
plinqo
eye-detection
having
pong
staging
coolstorage
system-tray
program-transformation
clipboard-pictures
greensoftware
metaphone
corporate-policy

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