Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete blanko characters

Status
Not open for further replies.

krava

Programmer
Jun 4, 2007
48
YU
Hi,

I have datafile (comma separated) like this one

342, 0.00279, 0.01163, 3.03125
342, 0.00279, 0.01163, 3.03125
342, 0.00279, 0.01163, 3.03125
342, 0.00279, 0.01163, 3.03125
..................................

and I would like to delete empty spaces before numbers to have like

342,0.00279,0.01163,3.03125
342,0.00279,0.01163,3.03125
342,0.00279,0.01163,3.03125
342,0.00279,0.01163,3.03125
..................................


Do you have an idea how to do that in a simple way?

thanks
k






 
on unix?

not awk but:

[tt]tr -d ':blank:' </path/to/your/file >/path/to/your/[red]new[/red]file[/tt]



HTH,

p5wizard
 
sed 's!, *!,!g' /path/to/input > output

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
it does not work in this way ... sure the syntax is ok? I am trying to run it with in BASH like:

usage: cleanBlanko "inputFile.csv"
function cleanBlanko(){
for i in `find -name "$1" -print`; do
echo $i "=============>" "$(dirname $i)"/"$(basename $i .csv)"_delBl.csv;
tr -d ':blank:' <$i >"$(dirname $i)"/"$(basename $i .csv)"_delBl.csv;
done
}
 
it does not work
which error message at which line ?

BTW, Have you tried the sed way ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
sed way is ok ... thanks.

it tr way there is nothing reported just does not do the job
 
You've got to give find a starting dir:

[tt]for i in `find [red]/your/dir[/red] -name "$1" -print`; do[/tt]

Also, perhaps your tr doesn't understand the ':blank:' character class?

If so, use:

[tt]
tr -d ' [&rarr;]' <in >out
^^
||
|press tab here
press space here
[/tt]

or if it is just spaces in your CSV files:

[tt]
tr -d ' ' <in >out
^
|
press space here
[/tt]


HTH,

p5wizard
 
Hi

Well, that [tt]tr[/tt] syntax looks strange for me and my GNU [tt]tr[/tt] too.
Code:
[blue]master #[/blue] date | tr -d ':blank:'
Mo J 28 203810 EET 2008

[blue]master #[/blue] date | tr -d '[:blank:]'
MonJan2820:38:16EET2008

[blue]master #[/blue] tr --help | grep blank
  [:blank:]       all horizontal whitespace

Feherke.
 
And, as we are in the AWK Forum:
Code:
awk '{gsub(/, */,",")}1' /path/to/input > output

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks, Feherke. I stand corrected.

I tried it out on an AIX system, then instead of cutting/pasting, I just typed out my post...


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top