delete blank space in begining of line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting delete blank space in begining of line
# 1  
Old 05-07-2008
delete blank space in begining of line

Hi All,

below is my data file
file.txt
Code:
$$0     ServerA  LAN1    AAA     IT01    04/30/2008  09:16:26
$$0     ServerB  LAN1    AAA     IT02    04/30/2008  09:16:26

here $ is a blank space
how to delete first 2 blank spaces in a file.
# 2  
Old 05-07-2008
Code:
sed -e 's/^  //' file.txt>file.new

# 3  
Old 05-07-2008
using Perl:
Code:
perl -pi -e 's/^\s+//' filename

This User Gave Thanks to Yogesh Sawant For This Post:
# 4  
Old 05-07-2008
Code:
sed -e 's/^  //g' filename > newfile

Thanks
# 5  
Old 05-07-2008
Quote:
Originally Posted by namishtiwari
Code:
sed -e 's/^  //g' filename > newfile

Thanks

The "-e" and the "g" is redundant, he only wants to delete the first 2 spaces.
The "-e" is for combining multiple commands and the "g" is for global (more) substitutes on a line, this is sufficient:

Code:
sed 's/^  //' filename > newfile

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to delete blank line/s before and after a search pattern?

Hi, Test file x.txt below. This file is generated by a program that I unfortunately do not have control on how it gets presented/generated. create PACKAGE "XXX_INTERFACE_DEFECT_RPT_TEST" is TYPE refCursor IS REF CURSOR; Function queryRecords ( p_status varchar2, ... ... ... )... (4 Replies)
Discussion started by: newbie_01
4 Replies

2. Shell Programming and Scripting

Delete Numbers, Spaces, Special Character from the begining of the line of a file

Hi All, I want to keep the name of the songs with their respective extensions only. Sample Code ======== 03 Choti choti gaiya choti choti gaval.mp3 03---Brazil Dhol.mp3 03 PAYALIYA .mp3 04 - Isq Risk .mp3 04%20-%20Oh%20My%20Love(wapking.in).mp3 08 - A2 - Aasan Nahin Yahan .mp3 AE... (3 Replies)
Discussion started by: Pramod_009
3 Replies

3. Shell Programming and Scripting

Not delete space blank

Hi everyone, i need to "grep" a file with a string with space blanks, like this: grep "XXXX XX" file.txt The problem, i need put the "XXXX XX" in a string variable. When the script executes the grep, do: gresp XXXX XX file.txt How can i solve this problem? The... (5 Replies)
Discussion started by: Xedrox
5 Replies

4. Shell Programming and Scripting

awk until blank space and print next line

Hello and Happy New Year 2012! I have this example: 1,2,3 4,5,6 7,8,9 For that, I'm trying to get: 1,2,3 4,5,6 7,8,9 for that, I think this might work but doesnt work so far: awk '{for(i=1;i=NF;i++);sub(/\//,"",$i);print $i}' myfile (2 Replies)
Discussion started by: Gery
2 Replies

5. UNIX for Dummies Questions & Answers

how to add or delete blank space in .txt

dear all, i have a question. i have a data which looks like below rs123 AATTTTTGGGGGGCC... rs456 TTTTTTCCCCCCCCC... rs5767 TTTTTTTGGGGGGCC... rs89776 GGGGCCCCCCCCC... WHAT I WANT is adding blank space as below: rs123 AA TT TT TG GG GG GC ... rs456 TT TT TT CC CC CC CC ... rs5767... (3 Replies)
Discussion started by: forevertl
3 Replies

6. Shell Programming and Scripting

NULL in between, at begining or at end of line - convert to space

How to replace null with space? I want to make each line with 80 characters. If any line contains only 5 characters and remaining is null, then i want to make it as 80 characrets where 5 is original characters and remaining 75 characters will be null.. NULL can come in between the line,... (3 Replies)
Discussion started by: Amit.Sagpariya
3 Replies

7. Shell Programming and Scripting

Delete last blank line.

I need to delete the last line only if its blank not otherwise. (3 Replies)
Discussion started by: dinjo_jo
3 Replies

8. Solaris

deleting blank space in beginning of line in vi

How can we delete all the blank spaces in the beginning of some lines in a text in vi? Thanks, (2 Replies)
Discussion started by: Pouchie1
2 Replies

9. Shell Programming and Scripting

sed: delete regex line and next line if blank

Hi, I want to write a sed script which from batiato: batiato/giubbe: pip_b.2.txt pip_b.3.txt pip_b.3mmm.txt bennato: bennato/peterpan: 123.txt consoli: pip_a.12.txt daniele: (2 Replies)
Discussion started by: one71
2 Replies

10. Shell Programming and Scripting

how to delete a first blank line from the file

I have a file which has the first blank line: sundev22$cat /t1/bin/startallocs /t1/bin/startallocsys 123 sundev22$ Is there a command to remove this first blank line? Thanks for help -A (4 Replies)
Discussion started by: aoussenko
4 Replies
Login or Register to Ask a Question