How to remove commas in the middle of a specific line in a file in linux/unix

Classified

Someone was trying to be helpful in their test description. However, they added commas to the description so that when the test description is outputted to the log file, the results have extra commas. This makes it difficult to parse the results since the number of commas vary in the results file.

I want to use sed and go into the test files to remove the commas from the description so we don't get bitten in the butt anymore, but I'm not sure what the regex should look like since I need to preserve everything else and remove just the commas. The line is from a jmeter jmx file.

Here are a few sample lines:

1 comma

HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="avgRespTime inst = green, 12 hr" enabled="true">

2 commas

HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="avgRespTime, inst = network, 2 days" enabled="true">

Can someone give me a hint on how to search for this line and remove only commas while keeping everything else intact? Thanks in advance for any help you can give me.

EDIT: There might be other lines in the jmx file that contain a comma too so I can't blindly say something like:

sed -i 's/,//g' file.jmx
anubhava

You can use tr to remove all commas from a given string:

s='HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="avgRespTime, inst = network, 2 days" enabled="true">'
tr -d <<< "$s"

Or to change it inline using sed in all the lines that have HTTPSamplerProxy text :

sed -i.bak '/HTTPSamplerProxy/s/,//g' file

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to remove a specific, duplicated line within a file?

How to remove line with specific string from file

How to remove a blank line in text file after deleting a specific line?

How to delete (remove) a specific line of a text file based on the line number?

How to remove the extra commas from a csv file?

How to remove line matching specific pattern from a file

How to remove line containing a specific string from file?

How do I remove a specific line from a text file in python

How to remove every line starting with specific string from log file?

How to remove a line from csv file if it contains a specific word

How to append a string to one specific line and remove a string from another specific line in a file?

How to write a line of text into the middle of a file?

How to remove a specific line that contains a specific string?

Remove lines with specific line number specified in a file

Remove specific line from txt file

Remove a specific line from a .txt file

How to remove stronger line in the middle of graph for android MPAndroidChart

Tcl How to write data to a specific line number in the middle of operating

How to remove commas from CSV file using Vi

How can I remove extra commas in a CSV file with php

How to remove commas in all lines of csv file python

How to remove specific number of line from existing file and create new text file

How can I remove a specific line from a file only if there are other lines in the file?

Replace specific commas in a csv file

How to read a specific line in a file?

How to read specific line of file?

How to delete a specific line in a file?

How to write to a specific line of a file?

How to remove the rest of the line after a specific string