Browse
Hewlett Packard Enterprise Community
Sign In
Help
Community Home
>
Servers and Operating Systems
>
Operating Systems
>
Operating System - HP-UX
>
Add a line after each 1000 records
Options
Subscribe to RSS Feed
Mark Topic as New
Mark Topic as Read
Float this Topic for Current User
Bookmark
Subscribe
Printer Friendly Page
All community
This category
This board
Knowledge base
Users
cancel
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for
Search instead for
Did you mean:
Add a line after each 1000 records
Highlighted
Muktha
Frequent Advisor
Mark as New
Bookmark
Subscribe
Subscribe to RSS Feed
Permalink
Print
Report Inappropriate Content
09-22-2008
04:27 AM
09-22-2008
04:27 AM
Add a line after each 1000 records
Hi all,
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
All forum topics
Previous Topic
Next Topic
9 REPLIES
9
Kenan Erdey
Honored Contributor
Mark as New
Bookmark
Subscribe
Subscribe to RSS Feed
Permalink
Print
Report Inappropriate Content
09-22-2008
04:41 AM
09-22-2008
04:41 AM
Re: Add a line after each 1000 records
Hi,
awk '{print $0;if (NR%1000==0) print "1k line seperator";}' input_file > output_file
Kenan.
Computers have lots of memory but no imagination
Tags
(1)
Tags:
awk
James R. Ferguson
Acclaimed Contributor
Mark as New
Bookmark
Subscribe
Subscribe to RSS Feed
Permalink
Print
Report Inappropriate Content
09-22-2008
04:42 AM
09-22-2008
04:42 AM
Re: Add a line after each 1000 records
Hi Muktha:
One way:
# perl -ple 'print "INSERTED" if ($. > 1 && $. % 1000 == 1)' file
Regards!
...JRF...
Tags
(1)
Tags:
Perl
James R. Ferguson
Acclaimed Contributor
Mark as New
Bookmark
Subscribe
Subscribe to RSS Feed
Permalink
Print
Report Inappropriate Content
09-22-2008
06:08 AM
09-22-2008
06:08 AM
Re: Add a line after each 1000 records
Hi (again):
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...
AZayed
Super Advisor
Mark as New
Bookmark
Subscribe
Subscribe to RSS Feed
Permalink
Print
Report Inappropriate Content
09-22-2008
10:51 AM
09-22-2008
10:51 AM
Re: Add a line after each 1000 records
Dear JRF,
Perl is not pre-installed in HP-UX by default, isn't it ?
Thanks
Success seems to be connected with action. Successful people keep moving. They make mistakes, but they don't quit.
James R. Ferguson
Acclaimed Contributor
Mark as New
Bookmark
Subscribe
Subscribe to RSS Feed
Permalink
Print
Report Inappropriate Content
09-22-2008
11:00 AM
09-22-2008
11:00 AM
Re: Add a line after each 1000 records
Hi (agan):
> 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...
Muktha
Frequent Advisor
Mark as New
Bookmark
Subscribe
Subscribe to RSS Feed
Permalink
Print
Report Inappropriate Content
09-22-2008
07:50 PM
09-22-2008
07:50 PM
Re: Add a line after each 1000 records
Hi,
Thanks to all.
Sorry to say that ,we should not use perl commands in our scripts.
Regards
Muktha
Muktha
Frequent Advisor
Mark as New
Bookmark
Subscribe
Subscribe to RSS Feed
Permalink
Print
Report Inappropriate Content
09-22-2008
07:52 PM
09-22-2008
07:52 PM
Re: Add a line after each 1000 records
Thank you very much Kanan...
awk command works fine.
And sorry to disturb you again. Could you please explain that?
Regards
Muktha
Dennis Handly
Acclaimed Contributor
Mark as New
Bookmark
Subscribe
Subscribe to RSS Feed
Permalink
Print
Report Inappropriate Content
09-22-2008
08:25 PM
09-22-2008
08:25 PM
Re: Add a line after each 1000 records
>awk '{print $0; if (NR % 1000 == 0) print "1k line separator"}' input_file
>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.
James R. Ferguson
Acclaimed Contributor
Mark as New
Bookmark
Subscribe
Subscribe to RSS Feed
Permalink
Print
Report Inappropriate Content
09-23-2008
03:58 AM
09-23-2008
03:58 AM
Re: Add a line after each 1000 records
Hi (again) Muktha:
> 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...