How to view large files without more or less
I have a rescue disk that doesn't include "more" or "less" - how can I examine large files?
I'd say to get a better rescue disk, but maybe this is some ancient SCO Unix system where you are lucky to have anything at all, so let's see what can be done.
Just two quick things first: are you sure you aren't just using a bad $PATH? Would a "chroot" to the hard drive help? NO? OK, then..
I suppose if you don't have "more", you probably don't have "vi", "vim", or "view" either, right?
Maybe you have "ed" or "sed"?
$ ed logs/access.log 257 1,25p .. lines from the file (CTRL-D) $ sed -n '25,50p' logs/access.log
You can try being quick with CTRL-S. If that will work for you, you might want to do "stty -ixany" so that you have to use CTRL-Q to restart output.
Maybe read it on paper?
cat /var/log/messages > /dev/lp0
Watch out for line endings - if this is a Unix file and the printer is not doing CR/LF translation, you'll get stair-stepped output. Echoing Escape-&k2G to a HP Laserjet will fix that. I think every printer has some way to do that, but it could require dip switches. You can change "stty onlcr opost" in a script to avoid that, but that won't work for a network printer. You can translate on the fly with "sed" :
sed 's/$/\r/' /var/log/messages > /dev/lp0
You could split it into pieces and look at them separately:
cd /tmp split -l 24 /var/log/syslog for i in xa* do cat i echo "press enter for next" read ak done
Do I need to remind you that if you know what you are looking for "grep" might work?
Good old dd can (clumsily) print out parts of files.
dd if=/var/log/syslog count=1 dd if=/var/log/syslog count=1 skip=1
Would just slowing things down be enough?
while read line do echo "$line" sleep 1 done
Or this slightly more complex script:
#!/bin/bash x=0; while read line do echo $line : $((x=$x+1)) stop=$(($x % 24)) if [ $stop -lt 1 ] then echo "Continue?"; read ak < /dev/tty fi done
That's a Bash version, for "sh" you'd need to do:
x=`expr $x + 1` stop=`expr $x % 24`
By the way, if you are trying to fix the poor machine, the possible loss of "vi" means it's time to brush up on "ed" and "sed". Yeah, I know: not fun, but if that's all you have..
If you have even less than that, it's time to get very creative:
# assuming you need to change line 6 of a file sed -n '1,5p' /etc/resolv.conf > /tmp/a echo "Nameserver 184.108.40.206" > /tmp/b sed -n '7,$p' /etc/resolv.conf > /tmp/c cat /tmp/[a-c] > /etc/resolv.conf
Though very clumsy, "dd" can edit text files in a similar way.
So, while not necessarily ideal, you can survive without "more" or "less" - more or less :-)
Got something to add? Send me email.
(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version
Increase ad revenue 50-250% with Ezoic