0

The empty line may contains other than comma also. for example:

file.csv

id,date,address
1,2-Oct,fhfhfhf
,,
"","",""
'','',''

result: file.csv

id,date,address
1,2-Oct,fhfhfhf

Thanks in Advance...

0

3 Answers 3

3

Simple sed approach:

sed '/^[^-[:alnum:]]/d' file

The output:

id,date,address
1,2-Oct,fhfhfhf
Sign up to request clarification or add additional context in comments.

Comments

1
$ grep "[^,'\"]" file
id,date,address
1,2-Oct,fhfhfhf

If that's not all you need then edit your question to include more truly representative sample input/output.

Comments

0

Input

$ cat file.csv 
id,date,address
1,2-Oct,fhfhfhf
,,
"","",""
'','',''

Output

$ awk -F, -v q="[\"']" 'FNR>1{ for(i=1; i<=NF; i++){ t=$i; gsub(q,"",t); if(t){print; next }} next }1' file.csv
id,date,address
1,2-Oct,fhfhfhf

Explanation

awk -F, -v q="[\"']" '                       # call awk set field separator and variable q
        FNR > 1 {                            # if no lines related to current file is greater than 1 then
                   for (i = 1; i <= NF; i++) # start loop through fields 
                   {
                     t = $i;                 # assign field contents to variable t
                     gsub(q, "", t);         # global substitution
                                             # suppress single/double quotes
                     if (t) {                # if still variable t has something
                                             # meaning row is not empty so
                       print;                # print current line
                       next                  # go to next line
                     }
                    }
                   next                      # all fields are empty 
                                             # so do not print, 
                                             # go to next line
               }1                            # does default operation print current line/row/record 
                                             # this is for printing header
                     ' file.csv

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.