- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Simple Script Problem - reordering
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2002 10:57 PM
07-23-2002 10:57 PM
I don't want it sorted, just reversed...
Thanks in advance.
Russ.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2002 11:05 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2002 11:07 PM
07-23-2002 11:07 PM
Re: Simple Script Problem - reordering
nl -ba -s"~" file|sort -r|cut -f2-256 -d"~"
Use umlaut or something else for field definition see man
steve Steel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2002 11:48 PM
07-23-2002 11:48 PM
Re: Simple Script Problem - reordering
this is yet another task for Perl ;-)
But beware, this is a resource greedy solution as it requires the size of your file from memory stack, since we store the whole file in an array first.
So you shouldn't do this with really big files:
perl -e '@tmp = reverse <>;print @tmp' /path/to/your/file
Unfortunately, if you have big files, something more elaborate is needed, which I imagine would require seek().
HTH
Ralph
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2002 12:01 AM
07-24-2002 12:01 AM
Re: Simple Script Problem - reordering
Thanks All.
INPUT=$1
OUTPUT=$2
rm -f $OUTPUT
LINES=`wc -l $INPUT|awk '{print $1}'`
i=0
while test i -lt $LINES
do
i=`expr $i + 1`
echo " $i \c"
tail -n $i $INPUT | head -n 1 | tee -a $OUTPUT
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2002 12:07 AM
07-24-2002 12:07 AM
Re: Simple Script Problem - reordering
you could try this rather simple solution:
#!/usr/bin/sh
# reverse order of inputlines in $1
PREVIOUS_FILE=/tmp/prev
if [ -w $PREVIOUS_FILE ]
then
rm $PREVIOUS_FILE
fi
touch $PREVIOUS_FILE
CURRENT_FILE=/tmp/curr
if [ -w $CURRENT_FILE ]
then
rm $CURRENT_FILE
fi
touch $CURRENT_FILE
cat $1| while read CURRENT
do
echo $CURRENT > $CURRENT_FILE
cat $PREVIOUS_FILE >> $CURRENT_FILE
cat $CURRENT_FILE > $PREVIOUS_FILE
done
cat $CURRENT_FILE
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2002 12:29 AM
07-24-2002 12:29 AM
Re: Simple Script Problem - reordering
try this
cat -n
regds
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2002 01:23 AM
07-24-2002 01:23 AM
Re: Simple Script Problem - reordering
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2002 02:26 AM
07-24-2002 02:26 AM
Re: Simple Script Problem - reordering
you could also try:
grep -n ^ input-file | sort -kr1n,1n | awk -F':' '{print $2}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2002 12:59 PM
07-24-2002 12:59 PM
Re: Simple Script Problem - reordering
i=1
cat file.txt|while read xx
do
buf[$i]=`echo $xx`
i=$((i+1))
done
v=$((i-1))
while true
do
if [ $v -ge 1 ];then
echo ${buf[$v]}
v=$((v-1))
else
exit
fi
done
Thanks
AR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2002 01:42 PM
07-24-2002 01:42 PM
Re: Simple Script Problem - reordering
Here's one way:
# awk '{array [NR]=$0}; END{for (i=NR;i>0;i--) print array [i]}' inputfile > outputfile
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2002 12:43 AM
07-25-2002 12:43 AM
Re: Simple Script Problem - reordering
I would prefer the solution f U.Sivakumar
because it follows my most important approach : Keep it simple
just use:
tail -10000000000 oldfile > newfile
it's a silly way just to use a very very big number for tail but IT WORKS and you get what you want.
As long as your file does not have that big amount of lines you will get the file "oldfile" listed into "newfile" in reverse order.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2002 05:36 AM
07-25-2002 05:36 AM
Re: Simple Script Problem - reordering
Try this:
ed yourfile <
w
EOD
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2002 06:35 AM
07-25-2002 06:35 AM
Re: Simple Script Problem - reordering
thanks for the hint towards File::ReadBackwards module from CPAN
http://search.cpan.org/doc/URI/File-ReadBackwards-0.97/ReadBackwards.pm
Haven't stumbled yet over this one.
Of course this is *much* better than what I suggested as a quick one-liner.
I will definitely install this one.
It's always worth to dig the CPAN first
:-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2002 07:15 AM
07-25-2002 07:15 AM
Re: Simple Script Problem - reordering
Tail DOES NOT reverse order display of files, simply takes the last "n" lines of the file to stdout.
I.E. (yes I clipped the last two lines of cat)
cat /etc/hosts
127.0.0.1 localhost
10.37.161.12 sh0su012 tr0su010 loghost
tail -2 /etc/hosts
127.0.0.1 localhost
10.37.161.12 sh0su012 tr0su010 loghost
Doh, they are identical....
Look at the other suggestions for your answers and ignore the suggestions of using the tail command.
Regards,
Shannon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2002 07:21 AM
07-25-2002 07:21 AM
Re: Simple Script Problem - reordering
If you say tail -1000000, tail does a sequential read and has to keep the last 1000000 lines in memory. Sometime tail doesn't allocate enough memory, and I've seen where it just drops off the remaining lines.
My 2 cents...
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2002 11:45 AM
07-25-2002 11:45 AM
Re: Simple Script Problem - reordering
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2002 09:44 PM
07-25-2002 09:44 PM
Re: Simple Script Problem - reordering
You got me !!!
Next time i'm hopefully a little bit mor carefull
:;-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2002 10:17 PM
07-25-2002 10:17 PM
Re: Simple Script Problem - reordering
Here are my 2 cens.
On Solaris, IBM-AIX and DIGITAL a mere
"tail -r /path/to/file/filename"
would do the job. On HP-UX "-r" option is not available.
Rgds..
Suhas.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2002 10:38 PM
07-25-2002 10:38 PM
Re: Simple Script Problem - reordering
I do agree that. I posted a theory that i have not tried practically. I regret , If i have hurted you all.
regards,
U.SivaKumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2002 10:43 PM
07-25-2002 10:43 PM
Re: Simple Script Problem - reordering
"For you two who said to use the tail command to do this, I have a suggestion for you. Know what you are saying before giving answers on the forums!"
To err is human, You can be more polite in pointing out other's mistake.
regards,
U.SivaKumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2002 11:12 PM
07-25-2002 11:12 PM
Re: Simple Script Problem - reordering
Shannon, maybe 9 points was excessive for the tail command, but it did point me to the solution of using tail to pick the last line and then looping backup one line at a time.. See my reply earlier.
So tail didn't work as suggested... but it did prove an answer.... and that what mattered to me.