Solved Script uses plain/html text email to correct indentations

May 2, 2012 at 17:38:15
Specs: Windows XP
Script which uses plain/html text email to correct indentations


We use a script to find out indentation errors in the scripts we write.
Then based on result(which we get as a plain/html text email), we need to correct indentations manually.

Can anyone help me with a shell script to correct all these in one go....


See More: Script uses plain/html text email to correct indentations

Report •

#1
May 3, 2012 at 07:33:49
What constitutes an indentation? Do you want to delete the leading white space on every line? This sed script does that:

sed -e 's,^ *,,' myfile.txt


Report •

#2
May 3, 2012 at 10:06:16
Indentations to be followed:
1. No tabs in the script
2. No trailing white spaces


Need a script which can correct this.


Report •

#3
May 3, 2012 at 12:55:56
✔ Best Answer
a way ....

#!/bin/ksh

# remove all tabs and remove trailing whitespace from files with txt extension
# send to tmp file and then rename the file
for file in *.txt
do
   sed -e 's/[  ]//g' -e 's/[   ]*$//' $file > ./tmp.file
   mv ./tmp.file $file
done

consider these issues:

1) In the sed command above, the first sed statement has an actual tab charcter between the brackets and the second sed statement has a space and an actual table between the brackets.

The newer versions of sed, especially GNU sed on Linux, recognizes \t as a tab so the sed command could be written like this:

sed -e 's/[\t]//g' -e 's/[ \t]*$//' $file

2) The GNU sed has a edit in place flag -i so you don't have to send the sed to a temp file and then rename with the mv command.


Report •
Related Solutions


Ask Question