File Parsing Magic
-
If windows, powershell has split and trim functions.
$this = $this.ToString().Split("name=",2)[1].Split(";",4)
$name = $this[0].split("=",2)[1]
$ip = $this[2].Trim("ip=") -
@scottalanmiller said in File Parsing Magic:
Put the file that you want to process into file2parse and this will do the rest...
#!/bin/bash while read line; do echo $(echo $line | cut -d'=' -f2 | cut -d';' -f1)";"$(echo $line | cut -d'=' -f4 | cut -d';' -f1) done < file2parse
OMG SAM you are the best!
Sorry for not being clear. This is all under Linux VMs on-prem in my own environment (XenServer).
-
@scottalanmiller said in File Parsing Magic:
Put the file that you want to process into file2parse and this will do the rest...
#!/bin/bash while read line; do echo $(echo $line | cut -d'=' -f2 | cut -d';' -f1)";"$(echo $line | cut -d'=' -f4 | cut -d';' -f1) done < file2parse
This works 75% of the time, but it looks like some log entries show when a user is syncing an item shared by another user, which does not result in the desired output.
mailbox.log.2016-04-19:2016-04-19 01:27:53,338 INFO [qtp509886383-480009:https://10.39.6.4:443/service/soap/SyncRequest] [[email protected];[email protected];mid=14;ip=10.39.253.62;ua=ZCO/8.6.0.1320 (6.1.7601 SP1 en-US) P9b4 T1404;] soap - SyncRequest elapsed=4
What happens here is you get the following:
Desired output is:
[email protected];10.39.253.62
-
That's because your log format changed. That second one has more fields in it.
-
@scottalanmiller said in File Parsing Magic:
Put the file that you want to process into file2parse and this will do the rest...
#!/bin/bash while read line; do echo $(echo $line | cut -d'=' -f2 | cut -d';' -f1)";"$(echo $line | cut -d'=' -f4 | cut -d';' -f1) done < file2parse
Wait, I think there is a more important question that needs to be answered now. If you echo an echo, do you get an echoed echo's echo, or do they just cancel each other out and build a strange uncomfortable silence?
-
@RamblingBiped said in File Parsing Magic:
@scottalanmiller said in File Parsing Magic:
Put the file that you want to process into file2parse and this will do the rest...
#!/bin/bash while read line; do echo $(echo $line | cut -d'=' -f2 | cut -d';' -f1)";"$(echo $line | cut -d'=' -f4 | cut -d';' -f1) done < file2parse
Wait, I think there is a more important question that needs to be answered now. If you echo an echo, do you get an echoed echo's echo, or do they just cancel each other out and build a strange uncomfortable silence?
And to follow up, if you simultaneously echo two echos from a single echo, will your head explode or somehow magically stay intact?
-
Understood. I need to figure out a way to parse the file so that the process finds "user=" and pulls everything after it until it hits the following ";", then finds "ip=" and pulls everything after it until it hits the following ";"
-
@anthonyh said in File Parsing Magic:
Understood. I need to figure out a way to parse the file so that the process finds "user=" and pulls everything after it until it hits the following ";", then finds "ip=" and pulls everything after it until it hits the following ";"
Yes, which is basically what I did but the cut command can only use a single character delimiter.
-
@scottalanmiller said in File Parsing Magic:
@anthonyh said in File Parsing Magic:
Understood. I need to figure out a way to parse the file so that the process finds "user=" and pulls everything after it until it hits the following ";", then finds "ip=" and pulls everything after it until it hits the following ";"
Yes, which is basically what I did but the cut command can only use a single character delimiter.
Could he pipe it into awk, use the "." as a delimeter and the print all fields preceding each "."?
-
I'm very much a Linux noob, so I don't know what command to use. But I'd just use a regular expression alone or perhaps in combination with some other command to get the desired text here. In Powershell I would use the -match operator and/or the Select-String cmdlet.