- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: AWK difficulties
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
тАО09-29-2010 06:44 AM
тАО09-29-2010 06:44 AM
It's the "end of the line" I do not understand
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-29-2010 06:55 AM
тАО09-29-2010 06:55 AM
Re: AWK difficulties
# X="a b c d e f g h i j k"
# echo $X|awk '{for (i=9;i
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-29-2010 07:14 AM
тАО09-29-2010 07:14 AM
SolutionSorry, the last post has a fence-post error. The code should have been:
# echo $X|awk '{for (i=9;i<=NF;i++) {printf "%s ",$i};printf "\n"
i j k
Now, this said, if you wanted to preserve the exact whitespace spaceing between fields you could use:
# awk '{print substr($0,index($0,$9))}' myfile
...as for example
# cat myfile
a b c d e f g h i j k
a b c d e f g h i j k
awk '{print substr($0,index($0,$9))}' myfile
i j k
i j k
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-29-2010 07:20 AM
тАО09-29-2010 07:20 AM
Re: AWK difficulties
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-29-2010 07:53 AM
тАО09-29-2010 07:53 AM
Re: AWK difficulties
In the first method JRF shows that would be : i=9;i<=NF;i++
The NF is the Number-of-Field = "the end"
In the second method JRF proposes to just look for the byte offset where field 9 starts, and use that as the start of a string to extract. I like that, notably to preserve spacing.
But be careful that field 9 is indeed unique.
I typically 'help' that by adding separators (spaces) around the target string.
$ X="a b c d e if g h i j k l m"
$ echo $X| awk '{print substr($0,index($0,$9))}'
if g h i j k l m
$ echo $X| awk '{print substr($0,index($0," " $9 " ") + 1)}'
i j k l m
Obligatory PERL variant....
$ echo $X| perl -lane 'print join " ",@F[8..@F]'
i j k l m
Print the join of a slice of the array @F, set up by -a, using a space to join.
The slice starts at element 8 ( Perl arrays are 0 based).
It ends at the scalar value for @F which is the number of elements in @F (but in a pinch 999 will work fine as well)
hth,
Hein
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-29-2010 10:14 AM
тАО09-29-2010 10:14 AM
Re: AWK difficulties
Your profile shows that you have assigned points to 60 of 436 responses to your questions. When you are satisfied with the help you have received, please assign points as a way of saying "thanks" and as a breadcrumb for future trollers:
http://forums.itrc.hp.com/service/forums/pageList.do?userId=CA238734&listType=unassigned&forumId=1
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-29-2010 10:27 AM
тАО09-29-2010 10:27 AM
Re: AWK difficulties
do
set -- $a
shift 6
echo $*
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-29-2010 01:20 PM
тАО09-29-2010 01:20 PM
Re: AWK difficulties
It suggest that we interpreted the question(s) different from the way you intended them.
Can you perhaps provide concrete input and output examples and show what you tried so far?
Can you humor me and explain why you believe that JRF did not really answer the question asked with the limit information available in the question?
Ditto for my further explanation?
I don't need no points, but would like to understand the large disconnect.
Personally I thought Laurent's suggestion was great although admittedly it is not awk as per subject line.
Cheers,
Hein
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-29-2010 01:36 PM
тАО09-29-2010 01:36 PM
Re: AWK difficulties
else
cut -d " " -f 9-
to the "end of the line" means usually for instance:
if the line is
1 2 3 4 5 6 7 8 9 10 11 12
$1 is 1
$2 is 2
....
$9 is 9
$9 to the end of the line is
9 10 11 12
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-29-2010 01:40 PM
тАО09-29-2010 01:40 PM