- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: use of cut in command
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
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
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-05-2017 08:41 PM
02-05-2017 08:41 PM
Can anybody see the issue?
I have the following commands:
$ x3=$(grep -i isend x.x | tr -s " " )
$ echo $x3
isEndOfStream = false
$ x3=$(grep -i isend x.x | tr -s " " | cut -d "=" -f 2 )
$ echo $x3
false
$ x3=$(grep -i isend x.x | tr -s " " | cut -d "=" -f 2 | cut -c1-5)
$ echo $x3
fals
Where is 'e'?
But if I further do this:
$ x4=$(echo $x3)
$ echo $x4
false
$ x4=$(echo $x3 | cut -c1-5)
$ echo $x4
false
I got the whole value (false).
Thanks for any explanation and workaround.
Noel
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2017 09:33 PM
02-05-2017 09:33 PM
Solution> Where is 'e'?
Your "cut -c1-5" command cut it off from " false".
pro3$ x3='isEndOfStream = false'
pro3$ echo "$x3" | cut -d "=" -f 2
false
(Note: " false" != "false".)
pro3$ x=' xxx '
pro3$ echo $x
xxx
pro3$ echo "$x"
xxx
Guess which one works more like what happens in your pipeline.
As for a work-around, it depends on how you'd like to get rid of that
extra space. As usual, many things are possible (once you see the extra
space).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2017 09:58 PM
02-06-2017 09:58 PM
Re: use of cut in command
Thanks Steven for the reply.
I also found out that there is an unprintable character (CR - ASCII 13) at the end of "false" in the file so I still need to use cut to get only the first 5 characters.
$ x=$(grep -i end x.x | tr -s " " | cut -d "=" -f 2)
$ echo $x
false
$ expr length $x
6
$ x1=$(echo $x | cut -c1-5)
$ echo $x1
false
$ expr length $x1
5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2017 10:37 PM
02-06-2017 10:37 PM
Re: use of cut in command
> I also found out that there is an unprintable character (CR - ASCII
> 13) at the end of "false" in the file so I still need to use cut to get
> only the first 5 characters.
You're already using "tr", so it'd be easy to have it translate a CR
("\r") into something more harmless, like, say, a space. And, of
course, "sed" can destroy spaces with ease:
mba$ x=' xxx '
mba$ echo "$x"
xxx
mba$ echo "$x" | sed -e 's/ //g'
xxx
If you really want exactly five characters, then "cut" is fine, but
if you want to trim off spaces and other junk, then counting characters
may not be the best way.