Print out first 3 strings in a specified column
Print out first 3 strings in a specified column
(OP)
Separating columns via multiple spaces...
awk -F '[[:space:]][[:space:]]+' '{ print $1, $7"/"$6, $12 }'
Each column of data will have multiple data separated by spaces..
Not sure how to print out only the first 3 items in $12....
Any idea's
Thanks....
Joe Despres
awk -F '[[:space:]][[:space:]]+' '{ print $1, $7"/"$6, $12 }'
Each column of data will have multiple data separated by spaces..
Not sure how to print out only the first 3 items in $12....
Any idea's
Thanks....
Joe Despres
RE: Print out first 3 strings in a specified column
So the fields are separated by two or more whitespace characters and sub-fields are separated by single whitespace characters.
The big question here is whether you need to preserve the original whitespaces. I mean, to keep space in the output where was space in the input and keep tab where was tab.
If not needed to preserve whitespaces as they were, is simple :
CODE --> any Awk
If need to preserve whitespaces, gets abit complicated, but still reasonably simple if only has to work in GNU Awk :
CODE --> GNU Awk
If need to preserve whitespaces and to be portable ( or at least work with something else than GNU Awk ) :
CODE --> any Awk
( As you can see, in GNU Awk you can use \s for [[:space:]] and \S for [^[:space:]]. That also works in original-awk ( available on Ubuntu, not sure about its origin ), but not in Mawk. There the closest alternative would be [ \t] for [[:space:]] and [^ \t] for [^[:space:]]. )
Feherke.
feherke.ga
RE: Print out first 3 strings in a specified column
I do like the ::---> '\\s\\s+'
Thanks!
Joe Despres
RE: Print out first 3 strings in a specified column
Sorry to hear that. Could you post some sample input and expected output ? And specify which Awk implementation / version are you using.
Feherke.
feherke.ga
RE: Print out first 3 strings in a specified column
GNU Awk 3.1.8
Using awk on a Avamar system :)
#### Here's the raw out put from the mccli command ::--->
CODE -->
#### Output desired ::--->
9145091880251509 Completed w/Exception(s) /xxxx/yyy.com Windows File System
9145091880251709 Completed w/Exception(s) /xxxx/yyy.com Windows VSS
9145083240268209 Completed w/Exception(s) /xxxx/yyy.com Windows File System
Basically I want to check for exceptions from yesterdays backup results... Will apply this same info to the failures as well..
Thanks....
Joe Despres
RE: Print out first 3 strings in a specified column
Then the field separator theory seems not good enough :
CODE --> fragment
As you have GNU Awk, I would say, better we use the match() function to collect the needed pieces. ( match()'s 3rd parameter is GNU extension. )
But having only limited information about the input ( I assume those "xxxx" are placeholders for sensitive data ), putting together the regular expression would be quite long. So I would suggest an off-topic solution : Perl, because it's regular expressions support non-greedy quantifiers.
CODE --> Perl
Actually the accent is on non-greedy modifiers, so any tool/language with PCRE would do it.
Feherke.
feherke.ga
RE: Print out first 3 strings in a specified column
That didn't work :(
Thanks! You shouldn't work on this any more...
Joe Despres
RE: Print out first 3 strings in a specified column
Well, it works for the sample input... I suppose the issue is with those "xxxx", which I try to match a \w+. If they contain non-word characters, those will break the matching.
Feherke.
feherke.ga
RE: Print out first 3 strings in a specified column
Thanks
Joe Despres
RE: Print out first 3 strings in a specified column
CODE -->
Each backup generates one set of this...
All I really need is to strip out all the tags and put the data on one line separated by a comma
Joe Despres
RE: Print out first 3 strings in a specified column
May I suggest another off-topic solution for that ? XMLStarlet :
CODE
Feherke.
feherke.ga
RE: Print out first 3 strings in a specified column
#### This seems to work ::--->
CODE -->
ugly enough to back a buzzard off a gut wagon!
#### ONE_Line.awk ::--->
CODE -->
My next goal is to grep out part of a column :)
Thanks....
Joe Despres