0

we have the following file

how alignment lines to the left side with sed or perl one line liner

more conf.env

# Extra ssh options.  Empty by default.
    export HADOOP_SSH_OPTS="-o ConnectTimeout=5 -o SendEnv=HADOOP_CONF_DIR"

# Where log files are stored.  $HADOOP_HOME/logs by default.
  export HADOOP_LOG_DIR={{hdfs_log_dir_prefix}}/$USER

# History server logs
               export HADOOP_MAPRED_LOG_DIR={{mapred_log_dir_prefix}}/$USER

# Where log files are stored in the secure data environment.
         export HADOOP_SECURE_DN_LOG_DIR={{hdfs_log_dir_prefix}}/$HADOOP_SECURE_DN_USER

   # File naming remote slave hosts.  $HADOOP_HOME/conf/slaves by default.
# export HADOOP_SLAVES=${HADOOP_HOME}/conf/slaves

expected results

more conf.env

# Extra ssh options.  Empty by default.
export HADOOP_SSH_OPTS="-o ConnectTimeout=5 -o SendEnv=HADOOP_CONF_DIR"

# Where log files are stored.  $HADOOP_HOME/logs by default.
export HADOOP_LOG_DIR={{hdfs_log_dir_prefix}}/$USER

# History server logs
export HADOOP_MAPRED_LOG_DIR={{mapred_log_dir_prefix}}/$USER

# Where log files are stored in the secure data environment.
export HADOOP_SECURE_DN_LOG_DIR={{hdfs_log_dir_prefix}}/$HADOOP_SECURE_DN_USER

# File naming remote slave hosts.  $HADOOP_HOME/conf/slaves by default.
# export HADOOP_SLAVES=${HADOOP_HOME}/conf/slaves

1 Answer 1

3

This will delete all spaces and tabs at the beginning of every line:

sed 's/^[ \t]*//'

where

  • ^ matches the beginning of a line
  • [ \t] matches a space or a tab
  • * makes the previous […] block work zero or more times, as many times as it can (so it can match multiple spaces and/or tabs)

The whole s/…// command replaces pattern (^[ \t]* in this case) with nothing.

Example use:

sed 's/^[ \t]*//' <input.txt >output.txt

or in place (note -i is not required by POSIX):

sed -i 's/^[ \t]*//' file.txt

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .