Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash script to remove dot end of each line

Tags:

bash

Unix command to remove dot at end of each line in file.

Sample rec in file

11234567                 0.
23456789              5569.
34567810                 1.
10162056                 0.
like image 447
user3347931 Avatar asked Mar 21 '14 21:03

user3347931


People also ask

What does [- Z $1 mean in bash?

$1 means an input argument and -z means non-defined or empty. You're testing whether an input argument to the script was defined when running the script. Follow this answer to receive notifications.

What does %% mean in bash?

The operator "%" will try to remove the shortest text matching the pattern, while "%%" tries to do it with the longest text matching.

How do you remove the last 3 characters on bash?

To remove the last n characters of a string, we can use the parameter expansion syntax ${str::-n} in the Bash shell. -n is the number of characters we need to remove from the end of a string.

How do I break a line in bash?

The most common way is to use the echo command. However, the printf command also works fine. Using the backslash character for newline “\n” is the conventional way.


2 Answers

Just use sed:

sed 's/\.$//' yourfile
  • Escape the special character . using \.
  • Put an achor $ to only remove it from the end.
  • To make infile changes use -i option of sed.
like image 122
jaypal singh Avatar answered Oct 16 '22 12:10

jaypal singh


 sed -e 's/\.$//'

done. (padding to make answer long enough. grumble)

like image 2
sehe Avatar answered Oct 16 '22 12:10

sehe