Solved

Flush Left Text File

Posted on 2013-12-19
1
240 Views
Last Modified: 2013-12-19
I am working with a text file that may or may not have parts of the text indented. I want to make sure that all of the text has no white space  to the left of the first non-whitespace character. In VI, I can just type "<<" to make this happen, but I need to be able to do this from a simple script. Is there a way to do this from a command line?

So for instance:

test1
  test2
     test3

Becomes:
test1
test2
test3
0
Comment
Question by:stakor
1 Comment
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
Comment Utility
perl -i.bak -pe 's/^\s+//' file
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now