Link to home
Start Free TrialLog in
Avatar of Simon336697
Simon336697Flag for Australia

asked on

Removing first and last lines, and blank spaces at the start or each line.

Hi guys hope you are all well.

Guys im trying to work out how to remove from the output,
1)The first and last lines eg.samid and dsget succeeded
2)The blank spaces at the start of each line.

D:\>dsquery group "<Full DN" | dsget group -samid

Produces the following output..

  samid
  Member Servers - Printer Operators
  Notes Server - Restore Folder Full Control
  a_bcs
  a_helpdesk
  a_sas
  Accounts - Unlock users
dsget succeeded

So that the output looks like below..

Member Servers - Printer Operators
Notes Server - Restore Folder Full Control
a_bcs
a_helpdesk
a_sas
Accounts - Unlock users


Any help greatly appreciated.
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

This is like bat file or such?
Are you directing this to a file like >output.txt ?


Try

>output.txt 2>nul
Avatar of Simon336697

ASKER

Hi mplungjan.
I am not directing this to a file.
I tried your suggestion but that made no difference mplungjan.
What do you do with te output?
Hi mplungjan,

It just displays to the window.

dsquery group "<Full DN" | dsget group -samid

SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hmm, similar to oBdA and bill there... called away before submitting, should have refreshed :-)

Steve
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
A rather lengthy way of doing a one line command as usual Paul...
Well spotted...

I didn't notice the sample data until I finished coding.

Not familiar with his command so hedged my bets and wrote output to file.

What was crucial to me during coding were:

   - spaces on the right are preserved (only LEFT spaces specified in question)

   - lines consisting wholly of spaces are trimmed to blank lines

   - blank lines are preserved

   - number of text lines in file are therefore, preserved

   - leading spaces trimmed from start of lines

   - first line removed

   - last line removed

So there's a real lot going on here... and well beyond the scope of a one-liner!
Nope.  One line is fine.

It is a standard AD query output.

He just wants to get rid of the first and last lines and the spaces, like he said.... there won't be any other spaces in the output, or blank lines, and the first and last lines will be as shown.

So one line suffices.... or Bill Prew's, or oBdA's which do the same but with a wrapper around.

Bed calls.

Steve
Guys thanks so much to all you brilliant people.
My apologies for the delay in getting back here.
Great but I surely did not give the actual answer, did I?
Avatar of Sudheer T
Sudheer T

Hi paultomasi,

@paultomasi , your code work fine but how to remove the trailing spaces from the output file. Seems like we have 3 spaces at the end. Also, request you to tell me how to output to a CSV file with a comma at the end to this output. Could you please help me in this aspect ASAP.

Current output :
Name1  
Name2  
Name3  
Desired output:
Name1,
Name2,
Name3,
Picking a 5 year old question to add a comment to probably not best way to get an answer.  Suggest make a new question and add a link to this one.

Steve