1753259 Members
4773 Online
108792 Solutions
New Discussion юеВ

Re: Script question

 
SOLVED
Go to solution
iranzo
Frequent Advisor

Script question

hello,
here my file content:
253 589 1235 4568 45682
456 87 1023 854
i want to sort this file in a list with
one column :
253
589
1235
4568
...
Have you a script idea ? thanks
Bonjour
5 REPLIES 5
Mark Grant
Honored Contributor

Re: Script question

Here's a simple answer

for i in `cat filename`; do echo $i; done | sort -r
Never preceed any demonstration with anything more predictive than "watch this"
Bharat Katkar
Honored Contributor

Re: Script question

Hi there,
# cat filename | xargs

This will output in one single row.
See if this helps.

OR

try with col command.
See man col
You need to know a lot to actually know how little you know
Bharat Katkar
Honored Contributor
Solution

Re: Script question

Hi there try this one, tested and works:

#!/usr/bin/ksh
list=`cat filename`
myfunct()
{
VAR11=$#
while true
do
if [ VAR11 -gt 0 ]
then
echo $1
shift
let VAR11=$VAR11-1
else
exit
fi
done
}
myfunct $list

Regards,
You need to know a lot to actually know how little you know
Mark Grant
Honored Contributor

Re: Script question

And just so we can get rid of the loop

cat tester | tr [:blank:] "\012" | sort -r
Never preceed any demonstration with anything more predictive than "watch this"
Mark Grant
Honored Contributor

Re: Script question

Sorry to be a pain but all references to "sort -r " should, of course, be "sort -n"
Never preceed any demonstration with anything more predictive than "watch this"