- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- how to add line no. to each line
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
тАО11-16-2004 02:16 PM
тАО11-16-2004 02:16 PM
How to add the line number to each line of a file? For example, i want to convert file1 to file2. Is there any command or have to write a script?
#vi file1
aaaaa
bbbbb
ccccc
#vi file2
1;aaaaa
2;bbbbb
3;ccccc
Thanks.
Regards.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-16-2004 02:21 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-16-2004 02:49 PM
тАО11-16-2004 02:49 PM
Re: how to add line no. to each line
sed =
Cheers
Rajeev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-16-2004 02:54 PM
тАО11-16-2004 02:54 PM
Re: how to add line no. to each line
nl -s ';' file1 > file2
Man nl for details.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-16-2004 03:09 PM
тАО11-16-2004 03:09 PM
Re: how to add line no. to each line
Cool Clay! I never knew that 'nl' command whereas I have it on a big sticker on the back of my car!
[(nl) - being the country 'plate' for the NetherLands]
If you have other things to do in the conversion/processing then an other weapon of choice might be awk:
awk '{print NR ";" $0}' file1 > file2
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-16-2004 04:30 PM
тАО11-16-2004 04:30 PM
Re: how to add line no. to each line
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-16-2004 04:51 PM
тАО11-16-2004 04:51 PM
Re: how to add line no. to each line
Esc
:nu
sks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-16-2004 06:16 PM
тАО11-16-2004 06:16 PM
Re: how to add line no. to each line
I miss, next to nl, the obvious 'pr' command in the mentioned list
# pr -t -n\;4 -w9999 file
# nl -s\; -ba -n file
are almost the same. Please check if nl did not add empty lines on page breaks.
The other solutions are much better, since they number all lines, don't add formatting to the page numbers, and just do what you want
# perl -pe's/^/$.;/' file
# awk '{print NR ";" $0}' file
# sed = file | sed 'N; s/\n/\;/'
I don't like the sed command, because it adds and removes lines, but it works evenly well
Enjoy, Have FUN! H.Merijn