Delete first blank colomns in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete first blank colomns in a file
# 1  
Old 06-18-2013
Delete first blank colomns in a file

I need sed/awk operation performed on this file contents, so that the first blank columns are deleted.

Code:
[server1.com]

  11.22.33.44
  asasoooooo

[server2.com]
 22.33.44.55
 asapppppppp


[server3.com]
 44.55.66.77
    SSSSSSSSS

The final output should be as follows.

Code:
[server1.com]
11.22.33.44
asasoooooo

[server2.com]
22.33.44.55
asapppppppp

[server3.com]
44.55.66.77
SSSSSSSSS

# 2  
Old 06-18-2013
Code:
sed 's/^[<b><tab>]*//' /path/to/infile > /path/to/outfile

Replace "<b>" and "<tab>" with literal blanks/tabs when you write that down.

I hope this helps.

bakunin
# 3  
Old 06-18-2013
make sure you support Unix.com and a local charity ...
Code:
awk '{print $1}' /dir/file

This User Gave Thanks to Just Ice For This Post:
# 4  
Old 06-18-2013
Code:
awk 'NF{A[++c]=$1}END{for(i=1;i<=c;i++) print (!(i%3)?A[i] RS:A[i])}' file

This User Gave Thanks to Yoda For This Post:
# 5  
Old 06-18-2013
Thanks Yoda and Just Ice.
# 6  
Old 06-18-2013
Code:
sed 's/^[[:blank:]]*//' infile > outfile

Code:
while read line; do echo "$line"; done < infile > outfile

This User Gave Thanks to MadeInGermany For This Post:
# 7  
Old 06-18-2013
MadeIngermany's solution works fine.

Code:
# cat asas
      Device #0
      Device #1
      Device #2

Correct result
Code:
# cat asas | sed 's/^[[:blank:]]*//'
Device #0
Device #1
Device #2

While this is wrong
Code:
# cat asas | awk '{print $1}'
Device
Device
Device

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Delete blank spaces and blank lines in a file

Hi Gurus, Somebody can say me how to delete blank spaces and blank lines in a file unix, please. Thank you for advanced. (10 Replies)
Discussion started by: systemoper
10 Replies

2. Shell Programming and Scripting

Delete blank line in regular file

Hi all, I have file1 with line blank e.g. $cat file1 aaa 111 222 333 444 bbb 555 666 777 888 ccc ddd 1010 1010 1010 eee then i need delete the lines blank (3 and 5) so show $cat file1 aaa 111 222 333 444 bbb 555 666 777 888 ddd 1010 1010 1010 (5 Replies)
Discussion started by: aav1307
5 Replies

3. Shell Programming and Scripting

Delete blank lines in a file

Hi All, I have a file and I need to delete the lines that are blank and is starting with some characters below. Something like below: Regular Ascii File: Line1: AGODA1 BUSAN||SK Lord Beach 4/6/2012 4/7/2012 68060 Line2: AGODA2 BUSAN||SK Beach Hotel 4/6/2012 4/7/2012 610200 Line3: ... (4 Replies)
Discussion started by: rkumar28
4 Replies

4. Shell Programming and Scripting

delete blank line from middle of a file

All, I have a file which contains two entry with spaces (either one or more than one space). ex. /tmp/scripts/sql CUST_YR_END_INI.sql /tmp/scripts/sql CUST_WK_END_INI.sql /tmp/scripts/sql CUST_MTH_END_INI.sql /tmp/scripts/sql CUST_YR_END_INC.sql now I want to... (11 Replies)
Discussion started by: anshu ranjan
11 Replies

5. Shell Programming and Scripting

Delete blank lines from a file

Hi, I want to use diff to compare two files in a Perl file. But one of the files has some blank lines at the end. So I want to delete the blank lines from the file firstly and then use diff to compare them. But I dont know how to delete the blank lines from the files. Meanwhile, the system is... (5 Replies)
Discussion started by: Damon_Qu
5 Replies

6. Shell Programming and Scripting

How to delete the blank file while running a script.

Hi All, When i am runing a script from home directory the output is fine, but whenever i am running a script from any of the directory the output is fine while a "Blank file" is created named as "1" in the particular directory. Will you please suggest any options to fix this problem. It... (1 Reply)
Discussion started by: r_jha17
1 Replies

7. Shell Programming and Scripting

how to delete blank rows in a log file

Help How to delete all blank rows in log file (4 Replies)
Discussion started by: suryanarayana
4 Replies

8. 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

9. UNIX for Dummies Questions & Answers

delete blank lines from a file

can anyone show me how to delete blank lines from a file. thanks in advance (2 Replies)
Discussion started by: sachin.gangadha
2 Replies

10. Shell Programming and Scripting

Delete blank lines at the end of file

I am attempting to delete blank lines in my file and I've used this command: sed '/^$/d' $file > $file.fixed all this seems to do is copy the file and not delete the blank lines located at the end of the file. Any assistance would be greatly appreciated. (3 Replies)
Discussion started by: TL56
3 Replies
Login or Register to Ask a Question