Removing the first space in a line
You may use sed
for this:
sed 's/ //' infile >outfile
This applies a substitution to all lines of the file infile
that will substitute the first space character with nothing (i.e. remove it). The output is stored in the file outfile
. With sed 's/ //N'
, where N
is an integer between 1 and 9, you can pick which space to remove.
If the line is in a shell variable, you could use
var="${var/ /}"
This uses the ${parameter/pattern/string}
parameter expansion in bash
to do the same thing as the sed
command, but on the value in $var
. The resulting string is, in this example, then stored back into $var
.