- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Ignore 1st adn 2nd
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
03-11-2007 07:56 PM
03-11-2007 07:56 PM
I am trying to loop through a text file and I want to ignore the 1st and the last line in the file. HOw can I achive this without using tail and head.
for example
START|
1|RECV1_PLCMM_1_YYYYMMDD_HHMMSS_DATA.TXT|
2|RECV1_PLCMM_2_YYYYMMDD_HHMMSS_DATA.TXT|
3|RECV1_PLCMM_3_YYYYMMDD_HHMMSS_DATA.TXT|
4|RECV1_PLCMM_4_YYYYMMDD_HHMMSS_DATA.TXT|
5|RECV1_PLCMM_5_YYYYMMDD_HHMMSS_DATA.TXT|
END|
I want to ignore START and END in the file.
Could u pls help me with this
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2007 08:03 PM
03-11-2007 08:03 PM
Re: Ignore 1st adn 2nd
perl -lane 'print if !/START/ && !/END/' < yourfile
you can bind this in a loop...
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2007 08:28 PM
03-11-2007 08:28 PM
Re: Ignore 1st adn 2nd
-Santosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2007 08:38 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2007 09:54 PM
03-11-2007 09:54 PM
Re: Ignore 1st adn 2nd
or if your requirement is not tied to START/END phrase:
# Get the number of lines in data file
a=`wc -l g.lis | cut -d' ' -f1`
# Subtract one for the last line
b=`echo "$a - 1" | bc`
# Echo all but the first and last line
sed -n "2,$b p" data.lis
Please also read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33 on how to reward any useful answers given to your questions.
So far you have not awarded any points !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2007 12:50 AM
03-12-2007 12:50 AM
Re: Ignore 1st adn 2nd
Start processing after the second to skip the first.
In perl:
perl -ne "print $last if $.>2; $last=$_" some-text-file
fwiw,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2007 12:57 AM
03-12-2007 12:57 AM
Re: Ignore 1st adn 2nd
Here's another generalized way to skip the first and the last record in a file. Notice that this is not dependent upon any pattern matching:
# perl -ne 'print if $. > 1 and !eof' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2007 02:00 AM
03-12-2007 02:00 AM
Re: Ignore 1st adn 2nd
If you won't accept a particular language for your solution, then *say so* when you ask for help so that we don't waste our time!!!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2007 02:31 AM
03-12-2007 02:31 AM