Delete the line started with nondigit or newline character


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Delete the line started with nondigit or newline character
# 1  
Old 02-16-2010
Delete the line started with nondigit or newline character

i want to delete the line which is not started with numeric in vim.

Code:
vim temp.txt

 Volume in drive D is DATA
 Volume Serial Number is 8C52-2055

 Directory of D:\data\notes

02/16/2010  03:09 PM    <DIR>          .
02/16/2010  03:09 PM    <DIR>          ..
09/11/1999  03:03 AM           327,680 AgentRunner.nsf
10/14/1999  10:42 PM            77,312 alog4.ntf

12/30/1999  04:26 AM           518,144 doclbm50.ntf
01/05/2000  09:02 AM           515,072 doclbs5.ntf
06/26/2001  11:03 PM           564,224 doclbw50.ntf
09/14/2006  09:40 AM    <DIR>          domino
08/02/2000  12:15 AM           693,248 us.med
09/14/2006  09:40 AM    <DIR>          W32
              42 File(s)     26,234,140 bytes
               7 Dir(s)  10,324,987,904 bytes free

if i go for
Code:
:%g/^\D/d

then it only remove the line which is not started with nondigit but some blank lines are not removed . Could it possible to find line started with nondigit or newline character so that we could remove it at the same instance .
Code:
:%g/^[\D\n]/d

this things is not working as ^ act as a negate character here.
Is there any solution for it.

Thank & Regards
Dina

Last edited by Scott; 02-16-2010 at 07:20 AM.. Reason: Code tags please...
# 2  
Old 02-16-2010
It's been a little bit hard but finally I can do it

Code:
:%!sed '/^[^0-9]/d;/^$/d'

I execute sed command using current file as input and to receive output also, in sed command I have two scripts, first one delete all lines that start with character different to digits (0-9), and secod script deletes empty lines
# 3  
Old 02-16-2010
Tools is grep what you are looking for?

Code:
>cat vim.txt
vim temp.txt

 Volume in drive D is DATA
 Volume Serial Number is 8C52-2055

 Directory of D:\data\notes

02/16/2010  03:09 PM    <DIR>          .
02/16/2010  03:09 PM    <DIR>          ..
09/11/1999  03:03 AM           327,680 AgentRunner.nsf
10/14/1999  10:42 PM            77,312 alog4.ntf

12/30/1999  04:26 AM           518,144 doclbm50.ntf
01/05/2000  09:02 AM           515,072 doclbs5.ntf
06/26/2001  11:03 PM           564,224 doclbw50.ntf
09/14/2006  09:40 AM    <DIR>          domino
08/02/2000  12:15 AM           693,248 us.med
09/14/2006  09:40 AM    <DIR>          W32
              42 File(s)     26,234,140 bytes
               7 Dir(s)  10,324,987,904 bytes free


>cat vim.txt | grep "^[0-9]"
02/16/2010  03:09 PM    <DIR>          .
02/16/2010  03:09 PM    <DIR>          ..
09/11/1999  03:03 AM           327,680 AgentRunner.nsf
10/14/1999  10:42 PM            77,312 alog4.ntf
12/30/1999  04:26 AM           518,144 doclbm50.ntf
01/05/2000  09:02 AM           515,072 doclbs5.ntf
06/26/2001  11:03 PM           564,224 doclbw50.ntf
09/14/2006  09:40 AM    <DIR>          domino
08/02/2000  12:15 AM           693,248 us.med
09/14/2006  09:40 AM    <DIR>          W32

>

# 4  
Old 02-16-2010
Code:
grep ^[01] temp.txt

# 5  
Old 02-17-2010
@ kcoder24

i got your point , But i need is there any regular expression to do both the number or space search at the first character of the line.
# 6  
Old 02-17-2010
Tools check for digit or space

Code:
>cat vim.txt | grep -e "^[0-9]" -e"^ "
 Volume in drive D is DATA
 Volume Serial Number is 8C52-2055
 Directory of D:\data\notes
02/16/2010  03:09 PM    <DIR>          .
02/16/2010  03:09 PM    <DIR>          ..
09/11/1999  03:03 AM           327,680 AgentRunner.nsf
10/14/1999  10:42 PM            77,312 alog4.ntf
12/30/1999  04:26 AM           518,144 doclbm50.ntf
01/05/2000  09:02 AM           515,072 doclbs5.ntf
06/26/2001  11:03 PM           564,224 doclbw50.ntf
09/14/2006  09:40 AM    <DIR>          domino
08/02/2000  12:15 AM           693,248 us.med
09/14/2006  09:40 AM    <DIR>          W32
              42 File(s)     26,234,140 bytes
               7 Dir(s)  10,324,987,904 bytes free

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove newline character if it is the only character in the entire file.?

I have a file which comes every day and the file data look's as below. Vi abc.txt a|b|c|d\n a|g|h|j\n Some times we receive the file with only a new line character in the file like vi abc.txt \n (8 Replies)
Discussion started by: rak Kundra
8 Replies

2. Shell Programming and Scripting

Count specific character of a file in each line and delete this character in a specific position

I will appreciate if you help me here in this script in Solaris Enviroment. Scenario: i have 2 files : 1) /tmp/TRANSACTIONS_DAILY_20180730.txt: 201807300000000004 201807300000000005 201807300000000006 201807300000000007 201807300000000008 2)... (10 Replies)
Discussion started by: teokon90
10 Replies

3. Shell Programming and Scripting

Sed: delete on each line before a character and after a character

Hi there, A total sed noob here. Is there a way using sed to delete everything before a character AND after another character on each line in a file? The deletion should also delete the indicating characters(here: an opening and a closing parenthesis). The original file would look like... (3 Replies)
Discussion started by: bnbsd
3 Replies

4. Shell Programming and Scripting

Delete line based on count of specific character

I'm looking for what I hope might be a one liner along these lines: sed '/a line with more than 3 pipes in it/d' I know how to get the pipe count in a string and store it in a variable, but I'm greedy enough to hope that it's possible via regex in the /.../d context. Am I asking too much? ... (5 Replies)
Discussion started by: tiggyboo
5 Replies

5. Shell Programming and Scripting

how to delete extra character in a line?

And I want to delete the characters longer than 20 for each line start with #. The other lines should remain the same. I think this can be done by sed. Could anyone help me with this? Thanks! my input file: #ZP_05494889.1_Clostridium_papyrosolvens... (3 Replies)
Discussion started by: ritacc
3 Replies

6. Shell Programming and Scripting

delete new line character ( - ) , korn shell

Hi guys , i need help so bad on this issue.. Basically i have to delete the line continuation symbol of first column variable and add the truncated part of that word in next line to first line. here i written sample 3 lines but originally i have bunch of lines in that file. client1_day- ... (3 Replies)
Discussion started by: chrismorgan
3 Replies

7. Shell Programming and Scripting

script to delete character in a line

Hi, Please help me to edit a file, with the following changes, 1) serach for XYZ , appears at the start of line, delete a character present in specified column number in a line. 2) This needs to be repeated in multiple rows and not the entire file Thanks (1 Reply)
Discussion started by: abc_81
1 Replies

8. UNIX for Dummies Questions & Answers

delete newline character between html tags

Hi, I have learned some of the Unix commands a way back and not sure of how to code them when needed in certain way, especially sed command. Here is my situation. I have an xml file with several tags. most of the tags start on the same line and end on the same line. However, data for some tags... (8 Replies)
Discussion started by: girish312
8 Replies

9. UNIX for Dummies Questions & Answers

delete a line based on first character of the line

Hi, I need to delete all lines in a file which starts with "|" character. Can some one assist me? Thanks (2 Replies)
Discussion started by: borncrazy
2 Replies

10. Shell Programming and Scripting

How to delete last character of a line?

Hello, I think I'm close to doing this, but I could be wrong. I have a string I would like to search for and delete the last character of the that line. This is what I have... sed 's/POHEAD\(.\)$//g' tempd > tempe The above works if I search for P, but that won't work. I need to search... (2 Replies)
Discussion started by: ctcuser
2 Replies
Login or Register to Ask a Question