DKumar
0
Q:

bash remove characters from end of every line

# Basic syntax using sed:
sed 's/..$//' input_file
# Where:
#	- 's///' means 's/search_for/replace_with/'
#	- '.' means any character
#	- $ means end of the line
# Putting it together, this sed statement means: replace any two 
#	characters at the end of every line with nothing. 

# Note, adapt this for your needs by changing the search pattern. 
#	E.g., by adding more '.'s, changing the search pattern, etc 
1
# Basic syntax:
cut -c n- input_file
# Where
#	- -c means "characters", as opposed to -f for "fields"
# 	- n is the number of characters to delete and n- means keep everything
#		past the nth character. (-n would mean keep everything up to the
#		nth character and just n means return the nth character)
1
echo "Hello: world" | cut -f1 -d":"
0
#!/bin/bash

#Make our variable
var="foo bar"

#Print it without the spaces
echo ${var//[[:blank:]]/}

#Output will be foobar
0

New to Communities?

Join the community