Hi all,
I have a ascii text file like this :
$cat a.txt
abc |12343 |xyakdfj |
x |323 ||
kr1 |13434343|234343 |
Is it possible to to get the file eleminating blank spaces?
output file :
abc|12343|xyakdfj|
x|323||
kr1|13434343|234343|
using korn shell or awk
thanks in advance
Krishna
system
January 10, 2002, 6:25am
2
cat a.txt | sed -e "s/ //g"
cat a.txt | awk 'gsub(" ", "")'
system
January 17, 2002, 5:41pm
3
That awk solution, with gsub as a pattern match, will print only lines where gsub changes the line, so you can lose lines.
To retain all your lines:
awk '{gsub(" ","");print}' a.txt
I'm not trying to be a jerk here, but there is not reason to be using "cat" in any of the above example.
Instead of
cat a.txt | sed -e "s/ //g"
you can do:
sed 's/ //g' a.txt
and for this one:
cat a.txt | awk 'gsub(" ", "")'
you can do:
awk 'gsub(" ","")' a.txt
You can always pipe to those commands, but there's no need to use cat to dump a file.
system
January 18, 2002, 8:48am
5
Yep, agree with that (and notice that my suggested correction dropped the cat).
Sure did...
I can't remember the URL to a page that has various awards for using cat too much... If I find it, I'll post back.
Try this if you don't want to use awk
cat <filename> | tr -d '" "'
j1yant
January 25, 2002, 12:09pm
8
Please try this
sed 's/ *//g' file
(Ensure that there are two spaces before * )
This will work to remove all spaces in file.