Remove lines if the first character is "|"


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Remove lines if the first character is "|"
# 1  
Old 01-06-2012
Remove lines if the first character is "|"

Hi.

I have a huge file (350 million lines).
I need to delete all lines in it that:

1. Begin with a pipe character -- '|'
2. Or have less than 5 pipe characters in the line

Have been searching for some SED/AWK help for this (which is faster btw on such a ginormous file?) but only found this, but this works with a number not a pipe character.

PHP Code:
On this website
 /
unix-advanced-expert-users/160025-deleting-lines-if-ith-character-x.html 

Much appreciate any pointers.
# 2  
Old 01-06-2012
Does not matter - the time is due to I/O. sed reads the file once as does awk.

Code:
awk -F '|'  ' /^|/ || NF<5 {next} {print } ' bigfile > newbigfile

# 3  
Old 01-07-2012
Quote:
Originally Posted by jim mcnamara
Does not matter - the time is due to I/O. sed reads the file once as does awk.

Code:
awk -F '|'  ' /^|/ || NF<5 {next} {print } ' bigfile > newbigfile


Thanks Jim. Doesn't work. The "newbigfile" is totally blank.


---------- Post updated at 07:58 AM ---------- Previous update was at 07:28 AM ----------

Found it. The first | has to be escaped by a back slash. So the command should be:

Code:
awk -F '|'  ' /^\|/ || NF<5 {next} {print } ' bigfile > newbigfile


Last edited by pkiula; 01-07-2012 at 11:20 AM..
# 4  
Old 01-09-2012
Try this

Code:
awk -F "|" '{if( NF>5 && $1 != "") print}' inputfile

# 5  
Old 01-09-2012
Hi Sorry to intrupt in this thread.
i am new to this form..
can any one please let me know how to create new thread?
# 6  
Old 01-09-2012
Go to the relevant forum and click on New Thread on top left of the forum.
This User Gave Thanks to tene For This Post:
# 7  
Old 01-09-2012
Thanks tene
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Remove a word that ends with special character "!"

Hi all. I want to use sed to remove a word that ends with "!" in the first page of a file. The word I want to remove is: "DNA!". I have search for an answer and nothing of what I found helped me. ~faizlo (2 Replies)
Discussion started by: faizlo
2 Replies

2. Shell Programming and Scripting

Remove word after special character "/"

Hi There, I have one requirement to remove word after character "/". Input file is 2017-07-12|02|user1l|domain1/userl|0 2017-07-12|02|user2|domain1/user2|5 2017-07-12|02|user3|domain2/user3|0 2017-07-12|02|user4|domain1/user4|432 and require OP file is ... (2 Replies)
Discussion started by: anshu ranjan
2 Replies

3. UNIX for Dummies Questions & Answers

Grep : Filter/Move All The Lines Containing Not More Than One "X" Character Into A Text File

Hi All It's me again with another huge txt files. :confused: What I have: - I have 33 huge txt files in a folder. - I have thousands of line in this txt file which contain many the letter "x" in them. - Some of them have more than one "x" character in the line. What I want to achieve:... (8 Replies)
Discussion started by: Nexeu
8 Replies

4. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

5. Shell Programming and Scripting

Remove ":" and join lines in outline file

I have a vim outliner file like this: Title title 2 :Testing now :testing 2 :testing 3 title 3 :testing :ttt :ttg Is there a way to use a script or command to remove... (7 Replies)
Discussion started by: jostber
7 Replies

6. Shell Programming and Scripting

Appending character "0" in vi editor for all lines between 1 and 40.

I have to append character "0" for lines between 1 and 40 in a file. I tried the following code. :s/^0,1,40/g Input: Output: (2 Replies)
Discussion started by: pinnacle
2 Replies

7. Shell Programming and Scripting

How to print range of lines using sed when pattern has special character "["

Hi, My input has much more lines, but few of them are below pin(IDF) { direction : input; drc_pinsigtype : signal; pin(SELDIV6) { direction : input; drc_pinsigtype : ... (3 Replies)
Discussion started by: nehashine
3 Replies

8. Shell Programming and Scripting

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

9. UNIX for Advanced & Expert Users

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

10. UNIX for Dummies Questions & Answers

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies
Login or Register to Ask a Question