|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Remove white space at the beginning of lines
Hi!
I store some data obtained with grep or awk in a file. The problem is that some lines have white space at the begining : [w h i t e s p a c e]line1 line2 [whitespace]line3 I use something like grep WORD INFILE >> OUTFILE awk [script] >> OUTFILE I would love if it were possible to remove the white whitout parsing the OUTFILE after the grep or awk command. Is there an option like I could put in the grep or awk saying "keep only what is at left of the white space"? Any better idea? Thanks a lot, Tipi |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
You could pipe it through a Perl one-liner pretty easily.
| perl -pe 's/^\s+//' Note: This will remove any leading whitespace. If the line is all whitespace, the \s+ will capture the newline character. |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Or with sed: Code:
sed 's/^ *//' file |
|
#4
|
|||
|
|||
|
Try this:
cat INFILE | sed 's/^[ \t]*//' > OUTFILE |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Ok, thanks a lot!
|
| Sponsored Links | ||
|
![]() |
| Tags |
| grep or |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Space at beginning of the line | Sara_84 | Shell Programming and Scripting | 2 | 03-17-2012 03:22 AM |
| remove white space from specific columns in text file | shelladdict | Shell Programming and Scripting | 8 | 05-10-2011 09:41 AM |
| How to remove white spaces from the beginning an end of a string in unix? | mady135 | Shell Programming and Scripting | 3 | 10-05-2010 11:39 AM |
| Extract lines between 2 strings add white space | dcfargo | Shell Programming and Scripting | 4 | 07-26-2010 12:29 PM |
| Add new lines with a space in beginning | Aejaz | UNIX for Advanced & Expert Users | 8 | 05-01-2008 12:21 PM |
|
|