[opensuse] Using sed to retrieve only the 2nd of 3 words on tab-separated line.
I have a long file full of tab-separated records. A couple samples lines: 99616256-ZIP-335231 378599456976549 4797677379\x097997/378507976549\x0977-\x09949776-791/ 99616256-ZIP-915437 4597093459474773 4770\x097428-84473-4597009474773-877-4-045270947 9 I'm only interested in the middle field: 378599456976549 4597093459474773 I'm thought I could use sed to strip off the first word via: sed -i "s|.*\t||" filename But that is deleting both of the first 2 fields. What's the right magic sed command? Thanks Greg -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On Sat, 5 Nov 2016 00:13, Greg Freemyer wrote:
I have a long file full of tab-separated records.
A couple samples lines:
99616256-ZIP-335231 378599456976549 4797677379\x097997/378507976549\x0977-\x09949776-791/ 99616256-ZIP-915437 4597093459474773 4770\x097428-84473-4597009474773-877-4-045270947 9
I'm only interested in the middle field:
378599456976549 4597093459474773
I'm thought I could use sed to strip off the first word via:
sed -i "s|.*\t||" filename
But that is deleting both of the first 2 fields.
What's the right magic sed command?
Ah! You forgot that the "*" is greedy, and takes everything from the start to the last possible match. I'd start by thinking about either using a two parter, or grouping. Two parter (remove from start up to and including first tab, remove from second tab to end): sed -e 's,^[^\t]*\t,,' -e 's,\t[^\t]*$,,' or, use grouping: sed -e 's,^[^\t]*\t\([^\t]*\)\t[^\t]*$,\1,' Does this give you the missing hint? - Yamaban. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On Freitag, 4. November 2016 19:13:27 CET Greg Freemyer wrote:
I have a long file full of tab-separated records.
A couple samples lines:
99616256-ZIP-335231 378599456976549 4797677379\x097997/378507976549\x0977-\x09949776-791/ 99616256-ZIP-915437 4597093459474773 4770\x097428-84473-4597009474773-877-4-045270947 9
I'm only interested in the middle field:
378599456976549 4597093459474773
I'm thought I could use sed to strip off the first word via:
cut(1) is made for this # cut -f 2 infile > outfile -- No character, however upright, is a match for constantly reiterated attacks, however false. -- Alexander Hamilton -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On Fri, Nov 4, 2016 at 9:15 PM, mararm
On Freitag, 4. November 2016 19:13:27 CET Greg Freemyer wrote:
I have a long file full of tab-separated records.
A couple samples lines:
99616256-ZIP-335231 378599456976549 4797677379\x097997/378507976549\x0977-\x09949776-791/ 99616256-ZIP-915437 4597093459474773 4770\x097428-84473-4597009474773-877-4-045270947 9
I'm only interested in the middle field:
378599456976549 4597093459474773
I'm thought I could use sed to strip off the first word via:
cut(1) is made for this
# cut -f 2 infile > outfile
I forgot it was that easy. Thanks Greg -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
Hello, On Fri, 04 Nov 2016, Greg Freemyer wrote:
I have a long file full of tab-separated records.
A couple samples lines:
99616256-ZIP-335231 378599456976549 4797677379\x097997/378507976549\x0977-\x09949776-791/
I'm only interested in the middle field:
378599456976549
I'm thought I could use sed to strip off the first word via:
sed -i "s|.*\t||" filename
But that is deleting both of the first 2 fields.
The RE ".*" is "greedy".
What's the right magic sed command?
's|^[^\t]*\t\([^\t]*\)\t.*#|\1|' HTH, -dnh -- Do infants have as much fun in infancy as adults do in adultery? -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
participants (4)
-
David Haller
-
Greg Freemyer
-
mararm
-
Yamaban