Delete a specific string with tr

intelinside picture intelinside · Apr 23, 2012 · Viewed 66.2k times · Source

Is it possible to delete a specific string with tr command in a UNIX-Shell? For example: If I type:

tr -d "1."

and the input is 1.1231, it would show 23 as an output, but I want it to show 1231 (notice only the first 1 has gone). How would I do that?

If you know a solution or a better way, please explain the syntax since I don't want to just copy&paste but also to learn.

I have huge problems with awk, so if you use this, please explain it even more.

Answer

Kevin Sjöberg picture Kevin Sjöberg · Apr 23, 2012

In your example above the cut command would suffice.

Example: echo '1.1231' | cut -d '.' -f 2 would return 1231.

For more information on cut, just type man cut.