Skip to main content
deleted 92 characters in body
Source Link
Rui F Ribeiro
  • 58k
  • 28
  • 156
  • 239

I put my hands up to being a complete beginner, so apologies if I'm doing this wrong.

Say I have the following data frame that continues indefinitely horizontally and vertically with negative numbers only in the odd columns:

-1 2 3 4 -5 9 2 3 -4 5 -6 11 

And I want the 2nd, 4th and 6th complete columns (or every even column) and the minus signs only from the 1st, 3rd, and 5th (or every odd column), so I get this:

- 2 4 - 9 3 - 5 - 11 

And eventually end up with this:

-2 4 -9 3 -5 -11 

So I need the values from the even columns unchanged and of the odd columns, if there's a negative value, keep the - only and if there's a positive value, discard it.

Is there a way to do this with awk/sed?

This is about a far as I get:

awk '{ for (i=2;i<=NF;i+=2) $i="" }1' FILE.txt | sed 's/[0-9,.]*//g' 

I put my hands up to being a complete beginner, so apologies if I'm doing this wrong.

Say I have the following data frame that continues indefinitely horizontally and vertically with negative numbers only in the odd columns:

-1 2 3 4 -5 9 2 3 -4 5 -6 11 

And I want the 2nd, 4th and 6th complete columns (or every even column) and the minus signs only from the 1st, 3rd, and 5th (or every odd column), so I get this:

- 2 4 - 9 3 - 5 - 11 

And eventually end up with this:

-2 4 -9 3 -5 -11 

So I need the values from the even columns unchanged and of the odd columns, if there's a negative value, keep the - only and if there's a positive value, discard it.

Is there a way to do this with awk/sed?

This is about a far as I get:

awk '{ for (i=2;i<=NF;i+=2) $i="" }1' FILE.txt | sed 's/[0-9,.]*//g' 

I have the following data frame that continues indefinitely horizontally and vertically with negative numbers only in the odd columns:

-1 2 3 4 -5 9 2 3 -4 5 -6 11 

And I want the 2nd, 4th and 6th complete columns (or every even column) and the minus signs only from the 1st, 3rd, and 5th (or every odd column), so I get this:

- 2 4 - 9 3 - 5 - 11 

And eventually end up with this:

-2 4 -9 3 -5 -11 

So I need the values from the even columns unchanged and of the odd columns, if there's a negative value, keep the - only and if there's a positive value, discard it.

Is there a way to do this with awk/sed?

This is about a far as I get:

awk '{ for (i=2;i<=NF;i+=2) $i="" }1' FILE.txt | sed 's/[0-9,.]*//g' 
edited tags
Link
don_crissti
  • 85.7k
  • 31
  • 234
  • 262
Tweeted twitter.com/#!/StackUnix/status/612962241793667072
added 28 characters in body
Source Link
Asfound
  • 147
  • 1
  • 8

I put my hands up to being a complete beginner, so apologies if I'm doing this wrong.

Say I have the following data frame that continues indefinitely horizontally and vertically with negative numbers only in the odd columns:

-1 2 3 4 -5 9 2 3 -4 5 -6 11 

And I want the 2nd, 4th and 6th complete columns (or every even column) and the minus signs only from the 1st, 3rd, and 5th (or every odd column), so I get this:

- 2 4 - 9 3 - 5 - 11 

And eventually end up with this:

-2 4 -9 3 -5 -11 

So I need the values from the even columns unchanged and of the odd columns, if there's a negative value, keep the - only and if there's a positive value, discard it.

Is there a way to do this with awk/sed?

This is about a far as I get:

awk '{ for (i=2;i<=NF;i+=2) $i="" }1' FILE.txt | sed 's/[0-9,.]*//g' 

I put my hands up to being a complete beginner, so apologies if I'm doing this wrong.

Say I have the following data frame that continues indefinitely with negative numbers only in the odd columns:

-1 2 3 4 -5 9 2 3 -4 5 -6 11 

And I want the 2nd, 4th and 6th complete columns (or every even column) and the minus signs only from the 1st, 3rd, and 5th (or every odd column), so I get this:

- 2 4 - 9 3 - 5 - 11 

And eventually end up with this:

-2 4 -9 3 -5 -11 

So I need the values from the even columns unchanged and of the odd columns, if there's a negative value, keep the - only and if there's a positive value, discard it.

Is there a way to do this with awk/sed?

This is about a far as I get:

awk '{ for (i=2;i<=NF;i+=2) $i="" }1' FILE.txt | sed 's/[0-9,.]*//g' 

I put my hands up to being a complete beginner, so apologies if I'm doing this wrong.

Say I have the following data frame that continues indefinitely horizontally and vertically with negative numbers only in the odd columns:

-1 2 3 4 -5 9 2 3 -4 5 -6 11 

And I want the 2nd, 4th and 6th complete columns (or every even column) and the minus signs only from the 1st, 3rd, and 5th (or every odd column), so I get this:

- 2 4 - 9 3 - 5 - 11 

And eventually end up with this:

-2 4 -9 3 -5 -11 

So I need the values from the even columns unchanged and of the odd columns, if there's a negative value, keep the - only and if there's a positive value, discard it.

Is there a way to do this with awk/sed?

This is about a far as I get:

awk '{ for (i=2;i<=NF;i+=2) $i="" }1' FILE.txt | sed 's/[0-9,.]*//g' 
added 208 characters in body
Source Link
Asfound
  • 147
  • 1
  • 8
Loading
added 38 characters in body
Source Link
Asfound
  • 147
  • 1
  • 8
Loading
deleted 35 characters in body
Source Link
Anthon
  • 81.4k
  • 42
  • 174
  • 228
Loading
edited tags
Link
terdon
  • 252.7k
  • 69
  • 481
  • 719
Loading
Source Link
Asfound
  • 147
  • 1
  • 8
Loading