Awk to remove Blank lines in pipedelimited


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk to remove Blank lines in pipedelimited
# 1  
Old 05-20-2009
Awk to remove Blank lines in pipedelimited

Awk to remove Blank lines in pipedelimited
Help me correct this.

Code:
nawk -F"|" '{a=$0; gsub(FS, "",a); if(length(a)) print}'  file1

Quote:
nawk: illegal primary in regular expression | at
input record number 1, file file1
source line number 1

Code:
nawk -F"|" '{gsub(FS, "",$0);if(length($0)) print}' file1

Quote:
nawk: illegal primary in regular expression | at
input record number 1, file file1
source line number 1
# 2  
Old 05-20-2009
Try...
Code:
nawk -F'|' '{if (NF > 0) print}'  file1

# 3  
Old 05-20-2009
Code:
awk  '{a=$0;gsub(/[|| ]/,"");if(length($0))print a}' file


-Devaraj Takhellambam
# 4  
Old 05-20-2009
Quote:
Originally Posted by devtakh
Code:
awk  '{a=$0;gsub(/[|| ]/,"");if(length($0))print a}' file


-Devaraj Takhellambam
I tried the below code this works
Code:
  nawk -F'[|]' '{a=$0; gsub(FS, "",a); if (length(a)) print }' file1

Why do i have to use [] please help
# 5  
Old 05-20-2009
Quote:
Originally Posted by pinnacle
I tried the below code this works
Code:
  nawk -F'[|]' '{a=$0; gsub(FS, "",a); if (length(a)) print }' file1

Why do i have to use [] please help

Not sure may be this is special condition for awk
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove Blank lines in VI

Hi, Which option is used to remove blank lines in VI (AIX). ? Regards, Siva (6 Replies)
Discussion started by: ksgnathan
6 Replies

2. UNIX and Linux Applications

remove all blank lines

When I 'vi' my test file I see some blank lines. However once I do :set list to display hidden characters, I see the empty lines literally like this: ^I$ How do I remove them? I cannot find a regex to match them. (3 Replies)
Discussion started by: alexsuv
3 Replies

3. Shell Programming and Scripting

How to remove blank lines

Hi, I am facing a problem related to removing blank lines from a text document. Input Error 17-05-2011 11:01:15 VisualSVN Server 2.1 1001 The following information was included with the event: line3 line4 Error 17-05-2011 11:00:25 VisualSVN Server 2.1 ... (13 Replies)
Discussion started by: mayursingru
13 Replies

4. Shell Programming and Scripting

remove blank lines and merge lines in shell

Hi, I'm not a expert in shell programming, so i've come here to take help from u gurus. I'm trying to tailor a csv file that i got to make it work for the LOAD FROM command. I've a datatable csv of the below format - --in file format xx,xx,xx ,xx , , , , ,,xx, xxxx,, ,, xxx,... (11 Replies)
Discussion started by: dvah
11 Replies

5. Shell Programming and Scripting

Remove blank lines

I really hope someone can help me with this. I have several php files from a forum that I run, that now for some reason have blank lines after every line. Is there an easy way to make a script that does the following: * If there are consecutive blank lines, delete all of them except one. * If... (9 Replies)
Discussion started by: KidCactus
9 Replies

6. Shell Programming and Scripting

Can't remove blank lines from a file

Hi Guys, I have been trying to remove blank lines from a file with no success. I tried using all the following options on the file: tr -s '\n' < abc.txt grep -v "^$" abc.txt sed '/^$/d' abc.txt sed '/./!d' abc.txt awk '/./' abc.txt The file is a text file. (11 Replies)
Discussion started by: npatwardhan
11 Replies

7. Shell Programming and Scripting

remove blank lines

I have joined 2 files. Join command worked fine. but the result showing extra blank lines. I tried to remove blank spaces by using awk (-- -42 RS= ORS="\n\n" file.txt) and sed (sed '/^ *$/d' file.txt)commands but didn't remove any Any suggestions plz:D 123 tab ....... ......tab .......234... (3 Replies)
Discussion started by: repinementer
3 Replies

8. UNIX for Advanced & Expert Users

How to Remove the unwanted Blank Lines

I have a file with the below data, i would like to remove the end blank lines with no data. I used the below commands but could not able to succeed, could you please shed some light. Commands Used: sed '/^$/d' input.txt > output.txt grep -v '^$' input.txt > output.txt input.txt file... (5 Replies)
Discussion started by: Ariean
5 Replies

9. Shell Programming and Scripting

Remove all blank lines in shell or awk.

Hi there, I want to trim space between lines in unix. I have a file named abc.txt with 2,00,000 lines.But useful are only a few. Please tell me how to delete the blank lines.:o (1 Reply)
Discussion started by: tushar_tus
1 Replies

10. UNIX for Dummies Questions & Answers

Remove blank lines

¿How can i remove blank lines between all lines in a long text file? Example WrongFile.txt : Line 1 Line 2 Line 3 CorrectFile.txt : Line 1 Line 2 Line 3 Thanks in advance :confused: (4 Replies)
Discussion started by: osymad
4 Replies
Login or Register to Ask a Question