Not able to delete white spaces from file !! Please help

Not able to delete white spaces from file !! Please help

Post by Polan » Thu, 22 Jun 2006 19:07:28



Guys,

I have an input file which is having some white spaces in begining of
its some lines .
I have executed sed commands as well as tr commands as well as  grep -v
"^$" against the file but no luck.
The file is as follows :
------------------------------------------------------------------------
058AKZ
059AKZ

045AKZ

A00008

-------------------------------------------------------------------------

These are TSM volume names on which i have to perform som eTSM actions
. These volumes should be one per each line without any white spaces (
or blank lines ) so that i can use hail+tail against each volume name

Reason of grep command not able to remove these blank lines is that
there are some leading spaces ( when i use :list in vi editor , it
shows spaces and then $ character ; not the $ character itself in the
begining of line )

Kindly advice to resolve this problem

Thanks

Polani

 
 
 

Not able to delete white spaces from file !! Please help

Post by Stephane Chazela » Thu, 22 Jun 2006 19:17:47



Quote:> Guys,

> I have an input file which is having some white spaces in begining of
> its some lines .
> I have executed sed commands as well as tr commands as well as  grep -v
> "^$" against the file but no luck.
> The file is as follows :
> ------------------------------------------------------------------------
> 058AKZ
> 059AKZ

> 045AKZ

> A00008

> -------------------------------------------------------------------------

[...]

Maybe that file is a MS-DOS like file, where every line ends in
a ^M character.

Try:

CR=`echo a | tr a '\15'`
grep "[^[:blank:]$CR]"

will return every line that contains any character that isn't a
blank nor a CR.

--
Stephane

 
 
 

Not able to delete white spaces from file !! Please help

Post by Polan » Thu, 22 Jun 2006 20:28:21


Hi
Infact it is not a DOS file . This file is created by multiple
eliminations of grep -v -e command on Unix System.

Now when i ran

#CR=`cat hh | tr hh '\15'`
#echo $CR
058AKZ 059AKZ 045AKZ A00008

So it is displaying as as single shell variable value which will not
suffice my requirement .

Kindly advice me how to solve this problem..

Many Thanks for help

Regards

Khurram



> > Guys,

> > I have an input file which is having some white spaces in begining of
> > its some lines .
> > I have executed sed commands as well as tr commands as well as  grep -v
> > "^$" against the file but no luck.
> > The file is as follows :
> > ------------------------------------------------------------------------
> > 058AKZ
> > 059AKZ

> > 045AKZ

> > A00008

> > -------------------------------------------------------------------------
> [...]

> Maybe that file is a MS-DOS like file, where every line ends in
> a ^M character.

> Try:

> CR=`echo a | tr a '\15'`
> grep "[^[:blank:]$CR]"

> will return every line that contains any character that isn't a
> blank nor a CR.

> --
> Stephane

 
 
 

Not able to delete white spaces from file !! Please help

Post by Stephane Chazela » Thu, 22 Jun 2006 20:33:08



[...]
Quote:>> CR=`echo a | tr a '\15'`
>> grep "[^[:blank:]$CR]"
[...]
> Infact it is not a DOS file . This file is created by multiple
> eliminations of grep -v -e command on Unix System.

> Now when i ran

> #CR=`cat hh | tr hh '\15'`
> #echo $CR
> 058AKZ 059AKZ 045AKZ A00008

> So it is displaying as as single shell variable value which will not
> suffice my requirement .

[...] [please don't top post]

You missed my point.

CR=`echo a | tr a '\15'`

or

CR=`printf '\015'`

is a way to store the CR character into the $CR variable, so
that you can then run:

grep "[^[:blank:]$CR]" < hh

To check if your file has invisible characters, try:

cat -vte hh | more

or

od -c hh | more

--
Stephane

 
 
 

Not able to delete white spaces from file !! Please help

Post by Robert Bono » Thu, 22 Jun 2006 20:33:22




>Guys,

>I have an input file which is having some white spaces in begining of
>its some lines .
>I have executed sed commands as well as tr commands as well as  grep -v
>"^$" against the file but no luck.
>The file is as follows :
>------------------------------------------------------------------------
>058AKZ
>059AKZ

>045AKZ

>A00008

>-------------------------------------------------------------------------

>These are TSM volume names on which i have to perform som eTSM actions
>. These volumes should be one per each line without any white spaces (
>or blank lines ) so that i can use hail+tail against each volume name

>Reason of grep command not able to remove these blank lines is that
>there are some leading spaces ( when i use :list in vi editor , it
>shows spaces and then $ character ; not the $ character itself in the
>begining of line )

>Kindly advice to resolve this problem

'grep -v'  *is* the answer.

You merely need to specify what you want to ignore, correctly.
"^$" deletes lines with _nothing_ on them.
Lines that have whitespace characters on the line are not matched.

you want:  "^[     ]*$"
    where there are two characters inside the '['/']' pair -- those two
    characters being a 'tab' (ASCII [HT]), and a 'space' (ASCII [SP]).

 
 
 

Not able to delete white spaces from file !! Please help

Post by Ed Morto » Thu, 22 Jun 2006 21:19:15



> Guys,

> I have an input file which is having some white spaces in begining of
> its some lines .
> I have executed sed commands as well as tr commands as well as  grep -v
> "^$" against the file but no luck.
> The file is as follows :
> ------------------------------------------------------------------------
> 058AKZ
> 059AKZ

> 045AKZ

> A00008

> -------------------------------------------------------------------------

> These are TSM volume names on which i have to perform som eTSM actions
> . These volumes should be one per each line without any white spaces (
> or blank lines ) so that i can use hail+tail against each volume name

> Reason of grep command not able to remove these blank lines is that
> there are some leading spaces ( when i use :list in vi editor , it
> shows spaces and then $ character ; not the $ character itself in the
> begining of line )

> Kindly advice to resolve this problem

> Thanks

> Polani

awk NF file

        Ed.

 
 
 

Not able to delete white spaces from file !! Please help

Post by Polan » Fri, 23 Jun 2006 15:59:42


Guys Many thanks

Both of the last two posts solve my problem

Thanks to all who help me

Polani



> > Guys,

> > I have an input file which is having some white spaces in begining of
> > its some lines .
> > I have executed sed commands as well as tr commands as well as  grep -v
> > "^$" against the file but no luck.
> > The file is as follows :
> > ------------------------------------------------------------------------
> > 058AKZ
> > 059AKZ

> > 045AKZ

> > A00008

> > -------------------------------------------------------------------------

> > These are TSM volume names on which i have to perform som eTSM actions
> > . These volumes should be one per each line without any white spaces (
> > or blank lines ) so that i can use hail+tail against each volume name

> > Reason of grep command not able to remove these blank lines is that
> > there are some leading spaces ( when i use :list in vi editor , it
> > shows spaces and then $ character ; not the $ character itself in the
> > begining of line )

> > Kindly advice to resolve this problem

> > Thanks

> > Polani

> awk NF file

>    Ed.