- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Add a line after each 1000 records
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
Discussions
Discussions
Forums
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
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
тАО09-22-2008 04:27 AM
тАО09-22-2008 04:27 AM
Add a line after each 1000 records
There are 10000 records in a file(10000 lines).I want to add a line after each 1000 records .Could you please help me to do?
Regards
Muktha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-22-2008 04:41 AM
тАО09-22-2008 04:41 AM
Re: Add a line after each 1000 records
awk '{print $0;if (NR%1000==0) print "1k line seperator";}' input_file > output_file
Kenan.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-22-2008 04:42 AM
тАО09-22-2008 04:42 AM
Re: Add a line after each 1000 records
One way:
# perl -ple 'print "INSERTED" if ($. > 1 && $. % 1000 == 1)' file
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-22-2008 06:08 AM
тАО09-22-2008 06:08 AM
Re: Add a line after each 1000 records
Now that I'v had coffee, this is much more consise:
# perl -ne 'print $_;print "INSERTED\n" if $. % 3 == 0' file
Should you desire to update in-place simply do:
# perl -ni.old -e 'print $_;print "INSERTED\n" if $. % 3 == 0' file
Your original 'file' will be preserved as 'file.old'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-22-2008 10:51 AM
тАО09-22-2008 10:51 AM
Re: Add a line after each 1000 records
Perl is not pre-installed in HP-UX by default, isn't it ?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-22-2008 11:00 AM
тАО09-22-2008 11:00 AM
Re: Add a line after each 1000 records
> Perl is not pre-installed in HP-UX by default, isn't it ?
There should be a viable copy of Perl on your server even if it is a bit old. Find it with:
# whereis perl
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-22-2008 07:50 PM
тАО09-22-2008 07:50 PM
Re: Add a line after each 1000 records
Thanks to all.
Sorry to say that ,we should not use perl commands in our scripts.
Regards
Muktha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-22-2008 07:52 PM
тАО09-22-2008 07:52 PM
Re: Add a line after each 1000 records
awk command works fine.
And sorry to disturb you again. Could you please explain that?
Regards
Muktha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-22-2008 08:25 PM
тАО09-22-2008 08:25 PM
Re: Add a line after each 1000 records
>Could you please explain that?
It prints the current record. If the current input record number (NR) divided by 1000 has a remainder 0, then print out a separator.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-23-2008 03:58 AM
тАО09-23-2008 03:58 AM
Re: Add a line after each 1000 records
> Sorry to say that ,we should not use perl commands in our scripts.
And just why would that be? The reason *can't* be portability since Perl has been ported to more platforms than most of us can even name:
http://www.cpan.org/ports/index.html
To deny yourself the use of an extremely powerful tool is crippling at best. Assembly language, anyone?
Regards!
...JRF...