Remove Space and blank line from file in UNIX shell script

I have below file. I want to remove space at begining of every line and then after also remove blank line from file.
I use below code for each operation.

sed -e 's/^[ \t]//' < check.txt > check1.txt
sed '/^\s
$/d' < check1.txt > check2.txt

above code not remove all the space and blank line. any one can help in this.

try

sed 's/^[ \t]\+//;/^$/d' file

And Please use code tags for code and data sample.

Using awk

cat check.txt
CREATE TABLE $SC.TMP_TBL --- first step (
 ALTER TABLE $SC.TMP_TBL LOCKSIZE TABLE APPEND ON
ERROR: While creating temp table TMP_TBL!
ERROR: While loading records into table Z_KD!
Loading of table Z_KD is successfull!
CREATE TABLE $SC.TMP_TBL AS
 ALTER TABLE $SC.TMP_TBL LOCKSIZE TABLE APPEND ON
ERROR: While creating temp table TMP_TBL!
ule3-Trial 3 to update RECHTSFORM
MERGE INTO $SC.Z_KD a USING (

ERROR: While loading records into table Z_KD(Rule3-Trial3)!
CREATE TABLE $SC.TMP_TBL
 ALTER TABLE $SC.TMP_TBL
awk 'NF {$1=$1;print}' check.txt
CREATE TABLE $SC.TMP_TBL --- first step (
ALTER TABLE $SC.TMP_TBL LOCKSIZE TABLE APPEND ON
ERROR: While creating temp table TMP_TBL!
ERROR: While loading records into table Z_KD!
Loading of table Z_KD is successfull!
CREATE TABLE $SC.TMP_TBL AS
ALTER TABLE $SC.TMP_TBL LOCKSIZE TABLE APPEND ON
ERROR: While creating temp table TMP_TBL!
ule3-Trial 3 to update RECHTSFORM
MERGE INTO $SC.Z_KD a USING (
ERROR: While loading records into table Z_KD(Rule3-Trial3)!
CREATE TABLE $SC.TMP_TBL
ALTER TABLE $SC.TMP_TBL
awk '$1=$1' infile

--ahamed

If line starts with 0 or 0.0 this will not work, line will be removed.

That's right Jotne.
The OP's data doesn't seem to have it. :wink:

--ahamed

Still code is not working on my pc.
i think its not a space its a tab.

Have you tried with my script ?

Which is your OS? Which shell are you using?

--ahamed

@Mohin Jain
Why did you delete the input in post#1. Its difficult to help without any date.
$1=$1 in awk also removes tabs, not only spaces.
So code should work.

Hi,
For space in general:

sed 's/^[[:space:]]\+//;/^$/d' file

Regards.

My script will remove space as well as tab from the input.

I agree, but The standard white-space characters are the following:
` ' Space character.
\f Form feed.
\n New-line.
\r Carriage return.
\t Horizontal tab.
\v Vertical tab.
And these are covered by [:space:].
Regards.