Skip to contentSkip to conversation

leading spaces in a text file.

DISCUSSION Matthew Stapleton 3 participants 3 messages Aug 24, 2002

lore
Share & tools
lore
#1 lore raw
In reply to Matthew Stapleton
Quoted 9 lines · Matthew Stapleton

At the beginning of each line there are leading spaces that i wish to get rid of.

Something like the following:

<leading spaces><line content>
<leading spaces><line content>
<leading spaces><line content>
<leading spaces><line content>

Oh. Every *line* is quite different from every *sentence*. Still, assuming the file uses Unix-style newlines, something about like

                tr "\n " "\n"

should get rid of the last one after you've used whatever you already use to reduce the multiple spaces to one.

I say "about like" because the cli command tr has less flexible pattern specification than the Perl-command tr, so I may have the details wrong ... but the basic idea is about right.

--
-------------------------------------------"Never tell me the odds!"--------
Ray Olszewski -- Han Solo
Palo Alto, California, USA [email protected]
-------------------------------------------------------------------------------

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

#2 lore raw
In reply to Matthew Stapleton

sed "s/^ *//" oldfilename > newfilename

Learn regular expressions. ;)

Quoted 11 lines · Matthew Stapleton

At the beginning of each line there are leading spaces that i wish to get rid of.

Something like the following:

<leading spaces><line content>
<leading spaces><line content>
<leading spaces><line content>
<leading spaces><line content>

Quoted 11 lines

Matthew Stapleton
====================================
http://webpages.marshall.edu/~staple12
Resistance is Futile!
====================================
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

Bryan Whitehead
SysAdmin - JPL - Interferometry Systems and Technology
Phone: 818 354 2903
[email protected]

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

#0 lore raw

At the beginning of each line there are leading spaces that i wish to get rid of.

Something like the following:

<leading spaces><line content>
<leading spaces><line content>
<leading spaces><line content>
<leading spaces><line content>

Matthew Stapleton
====================================
http://webpages.marshall.edu/~staple12
Resistance is Futile!
====================================
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs