- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Search the character by position
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
02-14-2008 02:55 AM
02-14-2008 02:55 AM
I want to get the nth character in a file.
Could you please help me to do so.
Regards
Muktha
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2008 03:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2008 03:33 AM
02-14-2008 03:33 AM
Re: Search the character by position
cut -c n file
might work
Can you be more specific - is the file a text file? Do you want the nth character on each line, or just the nth charcter on a specific line? If you file is data do you just want the nth byte in the file?
HTH
Duncan
I am an HPE Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2008 04:15 AM
02-14-2008 04:15 AM
Re: Search the character by position
Thanks for the response.
Its a text file.
'cut -c n filename' gives the nth character of each line.I want the nth character of the file , not each line.
Please help me to do so.
Regards
Muktha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2008 04:55 AM
02-14-2008 04:55 AM
Re: Search the character by position
What is the first character? 0? 1?
Does newline count as a character?
two possible solutions in perl:
Seek to target and destroy...
$ perl -le 'seek STDIN,(shift)-1,0; print substr <>,0,1' 27 < x
Stomp through file and count:
$ perl -le '$offset=shift; while (<>) { if ($offset < length) { print substr $_,$offset-1,1; last } else { $offset -= length}}' 27 < x
Enjoy!
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2008 08:31 PM
02-14-2008 08:31 PM
Re: Search the character by position
Can you give me another solution without using the perl command .
Regards
Muktha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2008 09:13 PM
02-14-2008 09:13 PM
Re: Search the character by position
Thanks for the reply.
It works fine.
Regards
Muktha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2008 10:09 PM
02-14-2008 10:09 PM
Re: Search the character by position
Thanks to all for the response.
Is there any way to grep the nth character?
Regards
Muktha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2008 11:41 PM
02-14-2008 11:41 PM
Re: Search the character by position
Well you can use HGH'g dd(1) fragment then compare the char with what you want.
Or you could use xd(1) then grep:
$xd -tc -N1 -j$(( N - 1)) file
0000000 s
0000001
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2008 02:11 AM
02-18-2008 02:11 AM
Re: Search the character by position
Thanks to all.