- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How to reverse a File
Categories
Company
Local Language
Forums
Discussions
Knowledge Base
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Knowledge Base
Forums
Discussions
- Cloud Mentoring and Education
- Software - General
- HPE OneView
- HPE Ezmeral Software platform
- HPE OpsRamp
Knowledge Base
Discussions
Forums
Discussions
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
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
12-30-2003 07:47 AM
12-30-2003 07:47 AM
How can i display a file upside down.. Ie the last line fist and fist line last...
any command for this?
Thanks,
George
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2003 07:51 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2003 08:05 AM
12-30-2003 08:05 AM
Re: How to reverse a File
# perl -e'print reverse<>' file
There is a faster way. From GNU file utils, there is a command called 'tac' (reverse of cat)
http://hpux.connect.org.uk/hppd/hpux/Gnu/coreutils-5.0.91/
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2003 08:08 AM
12-30-2003 08:08 AM
Re: How to reverse a File
# cat testfile
aaa
bbb
ccc
ddd
HERES' the command I use:
# cat testfile | sed '1!G;h;$!d'
ddd
ccc
bbb
aaa
- FHALILI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2003 08:14 AM
12-30-2003 08:14 AM
Re: How to reverse a File
awk ' BEGIN { i=0 }
{ printf "%d %s\n",i,$0 }'
Happy new year
Laurent
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2003 08:18 AM
12-30-2003 08:18 AM
Re: How to reverse a File
with smaller files you can use an ed command in a script. This works directly in the file itself, e.g.:
ed $1 <
w
EOF
try running the above with you file as $1.
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2003 08:20 AM
12-30-2003 08:20 AM
Re: How to reverse a File
I would have probably done it this way:
[start script code]
#!/bin/sh
echo "Enter the filename to reverse --> \c"
read filename
echo "Enter the desired new filename --> \c"
read newfilename
lines=`cat ${filename} |wc -l`
while [ ${lines} -gt 0 ]
do
echo `head -${lines} ${filename} |tail -n 1` >>${newfilename}
(( lines=${lines} - 1 ))
done
echo Finished!
[end script code]
So many more elegant (and short!) ways to do this.
Note to self... must learn perl.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2003 12:38 AM
12-31-2003 12:38 AM
Re: How to reverse a File
How many ways to do a single thing... Thank god for the ITRC..
Happy new year to all
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2003 01:31 AM
12-31-2003 01:31 AM
Re: How to reverse a File
1 : cat filename |awk '{ s[NR] = $0} END { for ( i = NR ; i >= 1 ; i-- ) {print s[i] } }'
2: KEEP THE MONITOR (Display Unit) REVERSE !!
Happy New Year
Kaps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2003 01:39 AM
12-31-2003 01:39 AM
Re: How to reverse a File
Those are all fine software methods for reversing the file. You can also do it using hardware.
1. Turn your monitor upside down.
2. cat filename
;)
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2004 11:37 PM
01-01-2004 11:37 PM
Re: How to reverse a File
cat testfile | pr -t -n | sort -nrk1,1 | cut -f2-
- where pr "-t" suppresses page title, "-n" adds line numbers
- where sort "-k1,1" specifies first field for sorting, "-n" specifies numeric sort, and "-r" specifies in reverse
- where cut "-f2-" means cut 2nd field and on
=:-) Alex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2004 12:48 AM
01-02-2004 12:48 AM
Re: How to reverse a File
grep -n '^.'
The same way, but using some different commands...
As for the up-side-down monitor: you'll have to alter your character set to up-side-down characters and do a rev instead of cat, otherwise the text is a bit hard to read... (rev prints the line right-to-left instead of left-to-right, for the ones who don't know the command)... ;-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2004 01:06 AM
01-02-2004 01:06 AM
Re: How to reverse a File
grepping for ^. will skip the empty lines in a file.
Enjoy, Have FUN! H.Merijn [ Who wonders about the point assignment in this thread. I just cannot grasp what the value diff per post is for the reader ... ]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2004 01:20 AM
01-02-2004 01:20 AM
Re: How to reverse a File
nl
Happy new year and the best wishes for 2004 (and beyond, of course).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2004 01:27 AM
01-02-2004 01:27 AM
Re: How to reverse a File
You need to add the "-ba" switches to nl, else again it loses blanks.
George
This came up a week earier, most of the solutions are similar to above.
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=9248
-- Graham