- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Numbering records with vi ( sequence number part o...
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
тАО12-04-2009 12:24 PM
тАО12-04-2009 12:24 PM
I need to edit a file with data where the first 3 characters are the record sequence. I took out one record in the middle of the file. How can renumber the records to restore the correct sequence using the vi editor? Can vi do that or only awk? I dont mean going record by record and change it.
Thanks for the answers.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-04-2009 02:04 PM
тАО12-04-2009 02:04 PM
Re: Numbering records with vi ( sequence number part of record )
If I understand your question correctly, no, 'vi' won't do the job. A possible 'awk' solution might look like:
# cat ./input
1 aaa
2 bbb
3 ccc
100 ddd
200 eee
300 fff
# awk '{printf "%3d%s\n",i++,substr($0,4)}' input
0 aaa
1 bbb
2 ccc
3 ddd
4 eee
5 fff
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-04-2009 02:19 PM
тАО12-04-2009 02:19 PM
SolutionOr should there just not be gaps after the sequence number for the first record?
If you need a zero-filled sequence number just add a 0 in front of the d in the format for the solution James posted:
$ awk '{printf "%03d%s\n",NR,substr($0,4)}' input > output
One of many perl solutions could be:
$ perl -pe 's/.../sprintf("%03d",$.)/e' input
or with the number 'exposed' in a variable...
$ perl -pe '$n=sprintf("%03d",$.); s/.../$n/' input > output
and with 'in place' substitution:
perl -i -pe '$n=sprintf("%03d",$.); s/.../$n/' input
Cheers,
Hein
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-04-2009 02:30 PM
тАО12-04-2009 02:30 PM
Re: Numbering records with vi ( sequence number part of record )
Yes, the sequence has to be 3 characters long, means zero filled on the left in values less than 100.
Thanks, have a nice weekend.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-04-2009 06:23 PM
тАО12-04-2009 06:23 PM