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
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
05-03-2004 05:43 AM
05-03-2004 05:43 AM
Read
I need to read the first line of the file and the last line of the file.
can i use head or tail for doing that?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2004 05:50 AM
05-03-2004 05:50 AM
Re: Read
head -1 your_file > some_new_file
tail -1 your_file >> some_new_file
Best regards,
dl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2004 05:56 AM
05-03-2004 05:56 AM
Re: Read
INFILE=myfile
FIRST=$(line < ${INFILE})
LAST=$(tail -n -1 ${INFILE})
echo "First: ${FIRST}"
echo "Last : ${LAST}"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2004 06:19 AM
05-03-2004 06:19 AM
Re: Read
set -A data `sed -ne '1p;$p'
echo Last line is ${data[1]}
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2004 06:24 AM
05-03-2004 06:24 AM
Re: Read
IFS="^J"
^J is what you get when you press control-v followed by CR.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2004 06:48 AM
05-03-2004 06:48 AM
Re: Read
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2004 05:07 PM
05-03-2004 05:07 PM
Re: Read
I like the sed solutions.
Here is a simple awk solution in case you need to do more then just print:
awk 'BEGIN {getline; print} END {print x} {x=$0}' < your-file
And a silly solution in perl:
$ perl -e 'while (<>) {print unless ($x); $x=$_} print $x' < your-file
- loop through the input, print the line uless you have remembered a line. This takes care of the first line. Remembering lines in $x. At the end, print the last line remembered... being the last line :-).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2004 09:12 PM
05-03-2004 09:12 PM
Re: Read
regds,
Kaps