Author Topic: Shorting CSV lines using a column.  (Read 866 times)

sakis_s

  • Community Member
  • Posts: 21
  • Hero Points: 0
  • Is everybody in? The ceremony is about to begin.
Shorting CSV lines using a column.
« on: February 04, 2020, 08:25:59 am »
Hi!
I have some .csv files including different columns.
e.g.


The question is how can i short lines of .csv using a column?
In the above example i would like to short the lines by using "00010101". All lines with column "00010101" have to go on top. Exactly like we're shorting in Excel.

Any help would much appreciated!

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 5549
  • Hero Points: 449
Re: Shorting CSV lines using a column.
« Reply #1 on: February 04, 2020, 01:37:15 pm »
There isn't a single macro to do this but you could do this in multiple steps.

I'm using non-GUI commands but there are GUI commands for this.

First delete all lines EXCEPT the lines that need to go to the top. You might need a fancier search string here.

keep-search /;00010101;/

Do a "Save As" to save these lines to a temporary file.

No open your original file again and delete the lines you want at the top.

delete-search /;00010101;/

Now you can use "File>Insert a File..." to insert the temp file at the top.

Hope this makes sense

sakis_s

  • Community Member
  • Posts: 21
  • Hero Points: 0
  • Is everybody in? The ceremony is about to begin.
Re: Shorting CSV lines using a column.
« Reply #2 on: February 04, 2020, 10:34:42 pm »
keep-search /;00010101;/

delete-search /;00010101;/

Thank you so much for your response! I get your point and seems to work for me however, i'm new to slickedit & don't know how i use "keep-search" & "delete-search". Is there any tutorial how to use these?

Dan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2514
  • Hero Points: 139
Re: Shorting CSV lines using a column.
« Reply #3 on: February 04, 2020, 10:49:27 pm »
keep-search /;00010101;/

delete-search /;00010101;/

Thank you so much for your response! I get your point and seems to work for me however, i'm new to slickedit & don't know how i use "keep-search" & "delete-search". Is there any tutorial how to use these?

There is a video about it: https://www.youtube.com/watch?v=P6WDBg4C2bY

sakis_s

  • Community Member
  • Posts: 21
  • Hero Points: 0
  • Is everybody in? The ceremony is about to begin.
Re: Shorting CSV lines using a column.
« Reply #4 on: February 04, 2020, 10:59:12 pm »
keep-search /;00010101;/

delete-search /;00010101;/

Thank you so much for your response! I get your point and seems to work for me however, i'm new to slickedit & don't know how i use "keep-search" & "delete-search". Is there any tutorial how to use these?

There is a video about it: https://www.youtube.com/watch?v=P6WDBg4C2bY

Thanks Dan! Just tried it & it returns "Unknown Command". Any ideas why?

Dan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2514
  • Hero Points: 139
Re: Shorting CSV lines using a column.
« Reply #5 on: February 04, 2020, 11:02:25 pm »
Can you copy exactly what you ran on the command line?

sakis_s

  • Community Member
  • Posts: 21
  • Hero Points: 0
  • Is everybody in? The ceremony is about to begin.
Re: Shorting CSV lines using a column.
« Reply #6 on: February 04, 2020, 11:04:20 pm »
Can you copy exactly what you ran on the command line?

keep-search /;00010101;/

Dan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2514
  • Hero Points: 139
Re: Shorting CSV lines using a column.
« Reply #7 on: February 04, 2020, 11:06:31 pm »
Can you copy exactly what you ran on the command line?

keep-search /;00010101;/

What version of SlickEdit are you running (Help>About SlickEdit)?

sakis_s

  • Community Member
  • Posts: 21
  • Hero Points: 0
  • Is everybody in? The ceremony is about to begin.
Re: Shorting CSV lines using a column.
« Reply #8 on: February 04, 2020, 11:08:12 pm »
What version of SlickEdit are you running (Help>About SlickEdit)?

SlickEdit Pro 2015 (v20.0.3.0 64-bit)

Dan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2514
  • Hero Points: 139
Re: Shorting CSV lines using a column.
« Reply #9 on: February 04, 2020, 11:12:53 pm »
This feature was added for 2016 or 2017.  To do it this way you would have to upgrade.

sakis_s

  • Community Member
  • Posts: 21
  • Hero Points: 0
  • Is everybody in? The ceremony is about to begin.
Re: Shorting CSV lines using a column.
« Reply #10 on: February 04, 2020, 11:14:16 pm »
This feature was added for 2016 or 2017.  To do it this way you would have to upgrade.

Oh ok, i'll do! Thank you so much for the info Dan. Your help is really appreciated!

Dan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2514
  • Hero Points: 139
Re: Shorting CSV lines using a column.
« Reply #11 on: February 04, 2020, 11:20:31 pm »
You're welcome.

LBCEi

  • Senior Community Member
  • Posts: 203
  • Hero Points: 20
Re: Shorting CSV lines using a column.
« Reply #12 on: February 05, 2020, 02:18:40 am »
@sakis_s

If you could post an excerpt of your text file instead of a screenshot, we might be able to find a simple way to do this in your current version. 

I definitely would encourage you to upgrade, as SE has continued to add a lot of useful features recently.

I created what I think is a representative example of your input data and found that this procedure seems to do what you want to do:
  • Block select the column containing the '00010101' data that you want sorted to the top (right-click and drag the mouse or press Ctrl-B and use the arrow keys to select only the column containing the '00010101' values).
  • Replace ' ' (space) with '9' (Ctrl-H)
  • Tools>Sort...
  • Click the Sort on Selection, Ascending, and Numeric Sort options.  This should put the '00010101' rows at the top
  • Replace (Ctrl-H) '9999999' with '       ' (seven spaces).[\li]
This should work unless your data actually has seven nines '9999999'  in the real data.

I hope this helps.

Graeme

  • Senior Community Member
  • Posts: 2485
  • Hero Points: 325
Re: Shorting CSV lines using a column.
« Reply #13 on: February 05, 2020, 10:29:59 am »
Hi!
I have some .csv files including different columns.

The question is how can i short lines of .csv using a column?
In the above example i would like to short the lines by using "00010101". All lines with column "00010101" have to go on top. Exactly like we're shorting in Excel.

Any help would much appreciated!

Slickedit allows you to sort on a column.  If all the data has fixed width columns like it appears to, you can sort on the column by creating a column selection then use the sort command in the tools menu.  To create a column selection, right click with the mouse then drag  - see "block selections" in the help for other ways.

Once you have a column selection, click "sort" in the tools menu.  Make sure that "numeric sort" is unticked then click ok.

sakis_s

  • Community Member
  • Posts: 21
  • Hero Points: 0
  • Is everybody in? The ceremony is about to begin.
Re: Shorting CSV lines using a column.
« Reply #14 on: February 06, 2020, 10:27:33 am »
Thank you so much for your answers! I really appreciate your help!

Slickedit allows you to sort on a column.  If all the data has fixed width columns like it appears to, you can sort on the column by creating a column selection then use the sort command in the tools menu.  To create a column selection, right click with the mouse then drag  - see "block selections" in the help for other ways.

Once you have a column selection, click "sort" in the tools menu.  Make sure that "numeric sort" is unticked then click ok.

This is exactly what i was looking for! Thank you so much Graeme!