- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Cut column
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
01-14-2009 11:30 PM
01-14-2009 11:30 PM
p.s. the "------" is space
aaaaaa ------------------ testing1 ----------------- bbbb
aaaaa -----------------testing2 ----------bbbba
aaaaaaaaa ---------------testing3 -------------------------------------------- bbbd
aaaa -----------------testing4--bbbb
"
"
I would like to have a script to cut the content in the file to get the result , my desired result is as below
testing1
testing2
testing3
testing4
"
"
the condition to cut the content is
1. cut the content from the column 10 of each line
2. each line must be ended with a word that begins with bbb , so cut the content until bbb
3. erase all space ( -------- ) , then get the below result
testing1
testing2
testing3
testing4
"
"
Could advise the script ? thx in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2009 11:57 PM
01-14-2009 11:57 PM
Re: Cut column
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2009 11:58 PM
01-14-2009 11:58 PM
Re: Cut column
Thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2009 12:10 AM
01-15-2009 12:10 AM
Re: Cut column
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2009 12:42 AM
01-15-2009 12:42 AM
Re: Cut column
awk '{print $2}' |head -1
the above script is simple , but in my case , the words "testing1" is only example , in real case , it is a string that have space in it ( not just a word ) , so if I want to cut the culumn from column 2 to second last 2 column , what can i do ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2009 01:51 AM
01-15-2009 01:51 AM
Solution> Sorry , I have an adjustment, [...]
> [...] in real case [...]
Come back when you know what you want?
I'm not sure that the problem is well
specified, but something like the following
might be close to what you seek.
bash$ echo 'aaaaaa test ing 1 bbbb' | \
> sed -e 's/^.......... *//' -e 's/ *bbb[^ ]*$//'
test ing 1
The idea was to remove the first ten
characters ("^..........") plus any string
of spaces (" *"), and then to remove the
spaces leading up to "bbb" (" *bbb") and any
non-space characters between it and the end
of the line ("[^ ]*$").
(As I always say, "If you can't so it with
'sed', it's not worth doing.")
If you want only one line, "man head".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2009 02:33 AM
01-15-2009 02:33 AM
Re: Cut column
I would like to carify my requirement as below .
the file content
==========
aaaaaa ------------------ testing1 ----------------- bbbb
step 1
====
check if the line contain the word "test" , if not , then output the result "Do nothing" .
if have , then do step 2 .
step 2
====
cut the column from column 10 to last 10 column
so the result is
--------------- testing1 ------------
step 3
====
erase all space that in front of and in rear of the string "testing1" .
so the result is
testing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2009 09:29 AM
01-15-2009 09:29 AM
Re: Cut column
Will do. You're not paying enough to get
me to chase your ever-changing requirements.
I've provided a "sed" example which does
much of what you want (even now). If you
can't find someone to write your script for
you, perhaps you should try to study that
example, and adapt it to your (latest) needs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2009 05:13 PM
01-15-2009 05:13 PM
Re: Cut column
the my last message would be my final requirement ( sorry to change requirement as I get something confused ) , I will change it again.
I tried sed -e 's/^.......... *//' -e 's/ *bbb[^ ]*$//'
the result is
--------------- testing1 -----------------
if I want to cut column as the my message , could advise what can i do ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2009 09:28 PM
01-15-2009 09:28 PM
Re: Cut column
>
> the result is
> --------------- testing1 -----------------
I don't see how it could be. As I showed
before, I don't get those spaces.
Now, if they were tabs and not spaces, that
could change things. Of course, I can't see
what's really in your file, and there's no
reason to believe that you know what's in
there, either, and my psychic powers are too
weak to tell me, so I don't see what more I
can do.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2009 09:54 PM
01-15-2009 09:54 PM
Re: Cut column
>from column 10 to last 10 column
I'm not sure what "to last 10 column" means?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2009 11:02 PM
01-15-2009 11:02 PM
Re: Cut column
sorry to confused you , I attached a file , could please provide advise ? if still not clear , please point it out , I will explain more detail .
thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2009 12:58 AM
01-16-2009 12:58 AM
Re: Cut column
>that mean erase the character that from column 1 to 10 and from column 60 to 70
I assumed you wanted to just keep columns 11 to 60. And only wanted to remove the 10 columns from 61 to 70.
awk '
BEGIN {
getline
if ($0 ~ /aaaa/) {
str = substr($0, 11, 61-11)
# print str
sub("^ *", "", str) # strip leading spaces
# print str
sub(" *$", "", str) # strip trailing spaces
print str
} else {
print "Do nothing"
}
exit
} ' file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2009 01:19 AM
01-16-2009 01:19 AM
Re: Cut column
but what I hope to do is not to cut the column from column 60 to 70 , what I want is to cut the last ten column ( in the example , 60 -70 is last ten column , in real case , the length of the line is variable ) , could advise how to change it ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2009 01:23 AM
01-16-2009 01:23 AM
Re: Cut column
I would urge you to appreciate the folks who've helped you thus far, by assigning points. Refer to http://forums11.itrc.hp.com/service/forums/helptips.do?#28
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2009 02:04 AM
01-16-2009 02:04 AM
Re: Cut column
Why didn't you say exactly that. You said "to last 10 column", which (to) doesn't go together.
>(60 - 70 is last ten column
No your edge arithmetic is wrong, last 11 columns.
>could advise how to change it?
Trivial:
str = substr($0, 11, length($0)-2*10)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2009 07:08 PM
01-20-2009 07:08 PM
Re: Cut column
It run perfectly .
I still have one more question , the str is the result of the script , but it only output the result in the loop , can advise how to make the str result as a variable of the script ? like the below , I added echo $str at the end of it ( after exit ) , how to let it output the result of str ? thx
awk '
BEGIN {
getline
if ($0 ~ /aaaa/) {
str = substr($0, 11, 61-11)
# print str
sub("^ *", "", str) # strip leading spaces
# print str
sub(" *$", "", str) # strip trailing spaces
print str
} else {
print "Do nothing"
}
exit
} ' file
echo $str
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2009 07:55 PM
01-20-2009 07:55 PM
Re: Cut column
It might be better to use Steven's sed solution.
>how to let it output the result of str?
You wrap it in $():
str=$(awk '
BEGIN {
getline
if ($0 ~ /aaaa/) {
str = substr($0, 11, length($0)-2*10)
sub("^ *", "", str) # strip leading spaces
sub(" *$", "", str) # strip trailing spaces
print str
} else {
print "Do nothing"
}
exit
} ' file)
If our answers were helpful, please read the following about assigning points:
http://forums.itrc.hp.com/service/forums/helptips.do?#33
.. assigned points to 0 of 56 responses
http://forums.itrc.hp.com/service/forums/pageList.do?userId=WW165205&listType=unassigned&forumId=1
If you don't assign points, you run the risk of being struck off.