- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Awk: split into fields, and then split again
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
тАО06-04-2004 07:37 AM
тАО06-04-2004 07:37 AM
I have text files formatted like this:
===================================================
Logging begins at: [2004.05.31 00:24:20]
r [2004.05.31 00:24:34] (348) reason1: more text: foofoo STRING2: [9.8.7.5]
r [2004.05.31 00:24:47] (325) reason1: more text: var bar car STRING: txt.info.dot [4.3.2.1]
r [2004.05.31 00:25:20] (476) other reason text: variable lenght ZZZZZ: stuff.i.want.now [5.6.7.8]
r [2004.05.31 00:25:20] (391) reason1: some other text: foo BAR: stuff.wanted.txt [1.2.3.4] various text of various length
[and so on]
I can pull out the portion in the second square brackets with AWK like this:
> BEGIN { FS="[][]" }
> {print $4}
(NB: FS="[[]]" does not work!)
Now, what I'd like to do is split the $3 portion, colon-delimited, and get the last field. In the text above, that would be:
(blank)
txt.info.dot
stuff.i.want.now
stuff.wanted.txt
Then I'd like to print $4, (new_$3) like this
[1.2.3.4] (stuff.wanted.txt)
I've looked in the slender loris book, comp.lang.awk, and here, but either I am not searching properly or I'm to ignorant to understand what I'm reading.
Awk preferred; perl answers are nice, but no "one-liners," please. :-)
Thanks,
Rob
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-04-2004 07:44 AM
тАО06-04-2004 07:44 AM
Re: Awk: split into fields, and then split again
awk -F:
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-04-2004 07:46 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-04-2004 07:48 AM
тАО06-04-2004 07:48 AM
Re: Awk: split into fields, and then split again
So, would you do something like
BEGIN { FS="[][]" }
{
print $4
temp=$3
FS=:
print "("$NF")\n"
}
I wasn't able to get that to work.
what am I missing?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-04-2004 07:50 AM
тАО06-04-2004 07:50 AM
Re: Awk: split into fields, and then split again
awk -F: '{
split($4,a,"[");
printf("[%s,%s\n",a[2],a[1]);
}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-04-2004 07:52 AM
тАО06-04-2004 07:52 AM
Re: Awk: split into fields, and then split again
BEGIN { FS="[][]" }
{
print $4
temp=$3
FS=:
print "("$NF")\n"
}
I wasn't able to get that to work.
what am I missing?
no semicolon at the end of statement
print $4;
temp=$3;
etc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-04-2004 07:55 AM
тАО06-04-2004 07:55 AM
Re: Awk: split into fields, and then split again
not sure what your trying to do with this:
print "("$NF")\n"
print number of fields:
print NF;
print the last field:
print $NF;
usually i think what you want is to do this
printf("%s\n",$NF);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-04-2004 07:56 AM
тАО06-04-2004 07:56 AM
Re: Awk: split into fields, and then split again
BEGIN { FS="[][]" }
{
print $4
sizeOfArray =split($3,name,":");
print name[sizeOfArray];
}
Works mostly!
On some records it's returning too much; let me see why . . . .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-04-2004 08:00 AM
тАО06-04-2004 08:00 AM
Re: Awk: split into fields, and then split again
I'm not using the colon at first, because there is a variable number of colons involved.
The constants are: the SECOND square-bracketed field, and the LAST colon-delimited field prior to that 2nd [] field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-04-2004 08:12 AM
тАО06-04-2004 08:12 AM
Re: Awk: split into fields, and then split again
BEGIN { FS="[][]" }
match($1,"^r") >0 {
sizeOfArray =split($3,name,":");
print $4" ("name[sizeOfArray]")";
}
The split() is what did it.
Thanks to all who replied!
Rob