- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- cut specific characters
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
тАО05-24-2011 03:08 AM
тАО05-24-2011 03:08 AM
cut specific characters
$vi test.txt
apple
orange
pine
banana
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-24-2011 03:24 AM
тАО05-24-2011 03:24 AM
Re: cut specific characters
=====================
cat test.txt |head -2 |tail -1 |cut -c 2-4
you need to save it in a variable.
var=`cat /test |head -2 |tail -1 |cut -c 2-4`
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-24-2011 06:45 AM
тАО05-24-2011 06:45 AM
Re: cut specific characters
sed -ne "2,2p" test.txt|cut -c 2,4
if you want to assign it to variable to use it later
MYVARIABLE=$(sed -ne "2,2p" test.txt|cut -c 2,4)
$() construct is the newer and more appropriate form of the command quoted in backticks. FO the time being, both work the same way.
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-25-2011 03:10 AM
тАО05-25-2011 03:10 AM
Re: cut specific characters
awk 'NR == 2 { print substr ( $0, 2, 3 ) }' test.txt
Cheers
Jean-Philippe
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-28-2011 01:36 AM
тАО05-28-2011 01:36 AM
Re: cut specific characters
You may want to optimize this by adding "exit" so you don't read all zillion lines of the file:
awk 'NR == 2 { print substr($0, 2, 3); exit }' test.txt