Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing characters from grep output

Tags:

linux

grep

bash

I've been whittling down my grep output (which comes down to a listing of numbers that I intend to associate with other fields.) My problem is that numbers above 999 have commas in them, and I'm wondering how to print the output with out the commas.

so instead of the output being:

1,200,300 

it would just be:

1200300  

Any suggestions for an additional pipe command that I could add?

Thanks

like image 203
Sam Avatar asked Oct 01 '12 05:10

Sam


People also ask

How do I remove grep output?

The most simple way to exclude lines with a string or syntax match is by using grep and the -v flag. The output will be the example. txt text file but excluding any line that contains a string match with “ThisWord”. Use whichever works best for your particular workflow.

How do I remove a character from a string in Linux?

Remove Character from String Using cut Cut is a command-line tool commonly used to extract a portion of text from a string or file and print the result to a standard output. You can also use this command for removing characters from a string.

How do I remove the last 3 characters from a string in Linux?

In this method, you have to use the rev command. The rev command is used to reverse the line of string characterwise. Here, the rev command will reverse the string, and then the -c option will remove the first character. After this, the rev command will reverse the string again and you will get your output.

How do I ignore a string in grep?

Exclude Words and Patterns By default, grep is case-sensitive. This means that the uppercase and lowercase characters are treated as distinct. To ignore the case when searching, invoke grep with the -i option. If the search string includes spaces, you need to enclose it in single or double quotation marks.


2 Answers

Try this

< your command > | tr -d ',' 

tr will remove all commas

like image 194
Akhil Thayyil Avatar answered Sep 18 '22 15:09

Akhil Thayyil


 < your command > | sed -e 's/,//g' 

This will replace all commas with "nothing" without changing anything else.

like image 38
John3136 Avatar answered Sep 16 '22 15:09

John3136