I have a file with the following contents..say
123 abc 90and /[abd] 1009
from which i only need numbers to be printed.
like 123 90 1009
using any shell command.
Thanks.
I have a file with the following contents..say
123 abc 90and /[abd] 1009
from which i only need numbers to be printed.
like 123 90 1009
using any shell command.
Thanks.
$ perl -ne 'print $1," " while /(\d+)/g; print "\n"'
Thats nice Pludi. But I'd prefer that to be done in shell itself
not possible with shell command,awk or sed?
Possible: yes. Shorter? Probably not. And the Perl command integrates into a pipe or other shell sequence just as well as awk or sed.
> echo "123 abc 90and /[abd] 1009"
123 abc 90and /[abd] 1009
> echo "123 abc 90and /[abd] 1009" | tr -d "[:alpha:]|[:punct:]"
123 90 1009
> echo "123 abc 90and /[abd] 1009" | tr -d "[:alpha:]|[:punct:]" | tr -s " "
123 90 1009
No need to invoke an external program such as awk, sed or perl!
#!/usr/bin/ksh93
str="123 abc 90and /[abd] 1009"
echo "$str"
print ${str//[^0-9]/ }
Output:
$ ./demo
123 abc 90and /[abd] 1009
123 90 1009
$
All,
What if i have a huge file with nxn matrix of rows and columns and still i would like to have only numbers from every row ? I mean where no. of rows and columns are unpredictable. Any suggestions for that please.
rgds,
Srini
All of the above examples would (probably) still work, the only difference would be the performance and memory consumption.