Skip to main content

Timeline for Extract Values from Formatted Text

Current License: CC BY-SA 3.0

11 events
when toggle format what by license comment
Jan 15, 2016 at 13:01 comment added terdon @laktak yes, grep -E (egrep is deprecated) will work. OSX awk won't since it's not GNU awk. I have no idea why it wouldn't work for you on Ubuntu which does use GNU awk. I just tried on an Ubuntu VM and it worked as expected. Anyway, see updated answer for a more portable solution.
Jan 15, 2016 at 13:00 history edited terdon CC BY-SA 3.0
added 222 characters in body
Jan 15, 2016 at 12:02 comment added laktak Nope. Can't say what's wrong with it. Probably the awk version. egrep '^(\S+\s*){1,4}:' file shows the correct output. With awk it doesn't work on OS X either.
Jan 14, 2016 at 23:32 comment added terdon @laktak sorry, I'm on mobile so I can't test and can't really chat. Try replacing the \S+ with [^ +]. I don't see why it wouldn't work on an Ubuntu system though. Could you have spaces at the beginning of the line?
Jan 14, 2016 at 21:35 comment added laktak No, awk -F': *' '/^(\S+\s*){1,4}:/{gsub(/ /,"_",$1);print $1"=\""$2"\""}' file gives me no ouput (Ubuntu 15.10)
Jan 14, 2016 at 14:03 comment added terdon @laktak there shouldn't be any output when you . $(awk ...) or eval $(awk ...). Does the awk command by itself return anything? I mean just awk -F': *' '/^(\S+\s*){1,4}:/{gsub(/ /,"_",$1);print $1"=\""$2"\""}' file. If not, please ping me (@terdon) in /dev/chat and we can figure it out.
Jan 14, 2016 at 13:54 comment added laktak It works with awk -F': *' '(NF == 2) && ($1 ~ /^[A-Za-z0-9 ]+$/) {gsub(/ /,"_",$1);print $1"=\""$2"\""}' though.
Jan 14, 2016 at 13:54 comment added laktak Do I need a special version of awk for this? I get no output with your sample.
Jan 14, 2016 at 13:25 comment added laktak That's a neat solution. Thanks for the explanation!
Jan 14, 2016 at 13:23 vote accept laktak
Jan 14, 2016 at 10:42 history answered terdon CC BY-SA 3.0