Remove empty records


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove empty records
# 8  
Old 05-17-2012
Remove empty records

Hi Scrut,

I found this post very useful. Can you kindly explain this code like how each term is working here

Code:
awk '$2{print RS}$2' FS='\n' RS=\> ORS= infile

Sorry I am looking this post little late.

Thanks
Krsnadasa
# 9  
Old 05-17-2012
I think I wrote that a bit quickly. It is correct, but probably this equivalent code is probably somewhat easier to understand:
Code:
awk '$2{print RS $0}' FS='\n' RS=\> ORS= infile

This means:
  • use ">" as the records separator
  • use a newline as the field separator (so $1 is the header and $2 is the first line of the content)
  • do not use an output record separator (this is because we want it printed before instead of after the record, so we cannot use ORS for that)
  • If field 2 exists ($2{...}) then we are processing a record that consists of more than just a header, and we can print it preceded by the record separator (>) print RS $0
This User Gave Thanks to Scrutinizer For This Post:
# 10  
Old 05-17-2012
Remove empty records

Thanks Scrut,

Very useful information.. Smilie

Krsnadasa...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove empty files in home directory

how to remove empty files tried below command its remove only zero bytes not empty file which is greater then zero byte. for x in * do if then rm $x fi done (8 Replies)
Discussion started by: Kalia
8 Replies

2. Shell Programming and Scripting

How to remove empty line.?

Hi gurus, I have a script which works fine. https://www.unix.com/shell-programming-and-scripting/239347-how-pass-string-into-sql-query.html while read p do && para="'${p}'" || para="${para},'${p}'" done < filePlease use code tags as required by forum rules! a few days... (6 Replies)
Discussion started by: ken6503
6 Replies

3. Shell Programming and Scripting

Remove CR only on empty lines

Dear community, I have two output files that contains some CR # cat first.out 1234567890 598679857648566 9 1234567234 365837465873465 4 2342343243 289374982374894 4 # cat second.out 2342342342 ... (2 Replies)
Discussion started by: Lord Spectre
2 Replies

4. UNIX for Dummies Questions & Answers

remove empty field

Hi all ! I'm sure it is a basic question but I didn't find any threads that fit my need. How to remove empty fields with awk? Or in other words, how to shift all the fields after an empty field on the left? input: 1|2||3|4|5||6 wanted: 1|2|3|4|5|6 I tried: awk '{for(i=1; i<=NF;... (7 Replies)
Discussion started by: lucasvs
7 Replies

5. Shell Programming and Scripting

Remove empty line and the next one

Hi all, I'm trying to remove when this condition is met: an empty and the next one I'm using this command: sed '/^$/N; s/&//' file Which searches for an empty line, N attaches it to the next line, and substituing the combination with nothing.... but it is not working. What I'm missing... (1 Reply)
Discussion started by: meuser
1 Replies

6. UNIX for Dummies Questions & Answers

Grep specific records from a file of records that are separated by an empty line

Hi everyone. I am a newbie to Linux stuff. I have this kind of problem which couldn't solve alone. I have a text file with records separated by empty lines like this: ID: 20 Name: X Age: 19 ID: 21 Name: Z ID: 22 Email: xxx@yahoo.com Name: Y Age: 19 I want to grep records that... (4 Replies)
Discussion started by: Atrisa
4 Replies

7. Shell Programming and Scripting

using vi -c to remove empty lines

Hello: I searched here for "vi -c" but found no hits. How can I use vi -c to remove ALL empty lines, regardless of how many? I tried <code> vi -c ":g/^$/d | wq" filename </code> but I have to run it several times. This is NOT homework. :) Thanks for your time. (3 Replies)
Discussion started by: Habitual
3 Replies

8. UNIX for Dummies Questions & Answers

Remove only Empty Directories

I know this one was answered before in forum below - https://www.unix.com/unix-dummies-questions-answers/58210-removing-empty-folders-using-find-command.html But that one is closed & I have a question so here it goes. I want to delete all 2006 files. Now if along with the files, if the... (2 Replies)
Discussion started by: kedar.mehta
2 Replies

9. Shell Programming and Scripting

remove empty directory

Hi, I need to delete an empty directory in a temp directory except "dir5" (keep everything that is not empty). Plese advise. Here is an example of my directory. /dir/temp/ dir1 - delete if this is empty dir2 - delete if this is empty dir3 - delete if this is empty dir4 - delete if this... (7 Replies)
Discussion started by: sirrtuan
7 Replies

10. Solaris

Remove non empty dirctory

Hi, Any command or means to delete a director which is not empty rmdir or similar iam using Sun Solaries 2.6 :confused: I have many full directories with subdirectories and I can not go on emptying them all (5 Replies)
Discussion started by: adol3
5 Replies
Login or Register to Ask a Question