replacing blank lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting replacing blank lines
# 8  
Old 10-22-2008
i merged another code with the previous code u gave -
{print NF?$0:blankrow}blankrow=0{print NR $0 "\t"}
i do get the tabs.. but is it possible to make the tabs like a seperate field?
# 9  
Old 10-22-2008
Quote:
Originally Posted by rockiefx
i merged another code with the previous code u gave -
{print NF?$0:blankrow}blankrow=0{print NR $0 "\t"}
i do get the tabs.. but is it possible to make the tabs like a seperate field?
No need to merge, just use this:

Code:
 awk '$0=($0?$0:0)" \t"' infile

# 10  
Old 10-22-2008
the tabs are not alliged properly to make it a seperate field

output:
1(tab)
2(tab)
10(tab)

desired output:
1 (tab)
2 (tab)
3 (tab)
10 (tab)

Last edited by rockiefx; 10-22-2008 at 07:00 PM..
# 11  
Old 10-22-2008
Could post the output from the following command:

Code:
awk '$0=($0?$0:0)" \t"' infile|cat -te

I get this:
Code:
% awk '$0=($0?$0:0)" \t"' infile|cat -te
1 ^I$
2 ^I$
3 ^I$
0 ^I$
5 ^I$
0 ^I$
6 ^I$

digit -> space -> tab

Is this the desired result?

May be this illustrates it better:

Code:
% awk '$0=($0?$0:0)" \t"' infile|od -cbw4  
0000000   1      \t  \n
        061 040 011 012
0000004   2      \t  \n
        062 040 011 012
0000010   3      \t  \n
        063 040 011 012
0000014   0      \t  \n
        060 040 011 012
0000020   5      \t  \n
        065 040 011 012
0000024   0      \t  \n
        060 040 011 012
0000030   6      \t  \n
        066 040 011 012
0000034


Last edited by radoulov; 10-22-2008 at 07:05 PM..
# 12  
Old 10-22-2008
Or perhaps you want something like this?
(adjust the length if you need: -10, -15, -20 ...)

Code:
awk '$0=sprintf("%-15s",$0?$0:0)' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To check Blank Lines, Blank Records and Junk Characters in a File

Hi All Need Help I have a file with the below format (ABC.TXT) : ®¿¿ABCDHEJJSJJ|XCBJSKK01|M|7348974982790 HDFLJDKJSKJ|KJALKSD02|M|7378439274898 KJHSAJKHHJJ|LJDSAJKK03|F|9898982039999 (cont......) I need to write a script where it will check for : blank lines (between rows,before... (6 Replies)
Discussion started by: chatwithsaurav
6 Replies

2. UNIX for Advanced & Expert Users

Delete blank spaces and blank lines in a file

Hi Gurus, Somebody can say me how to delete blank spaces and blank lines in a file unix, please. Thank you for advanced. (10 Replies)
Discussion started by: systemoper
10 Replies

3. Shell Programming and Scripting

Reform Lines in File without blank lines and spaces

Hello All, I have a file with data as below. Each line consists of 21 fields. I am not able to load them back to the database. 50733339,"834","834 ","005010X279A1","N","Y","007977163","0001 ",30,"2110D ","EB ","EB007 ","2 ","Conditional Required Data Element Miss ing... (3 Replies)
Discussion started by: Praveenkulkarni
3 Replies

4. UNIX for Dummies Questions & Answers

Finding lines with a regular expression, replacing them with blank lines

So the tag for this forum says all newbies welcome... All I want to do is go through my file and find lines which contain a given string of characters then replace these with a blank line. I really tried to find a simple command to do this but failed. Here's what I did come up with though: ... (2 Replies)
Discussion started by: Golpette
2 Replies

5. Shell Programming and Scripting

Help in replacing two blank lines with two lines of diff data

Hi.. I'm facing a trouble in replacing two blank lines in a file using shell script... I used sed to search a line and insert two blank lines after the searchd line using the following sed command. sed "/data/{G;G;}/" filename . In the file, after data tag, two lines got inserted blank lines..... (4 Replies)
Discussion started by: arjun_arippa
4 Replies

6. Shell Programming and Scripting

Help in replacing two blank lines with two diff data

Hi.. I'm facing a trouble in replacing two blank lines in a file using shell script... I used sed to search a line and insert two blank lines after the searchd line using the following sed command. Sed "/data/{G;G;}/" filename. In the file, after data tag, two lines got inserted blank lines.. Now... (1 Reply)
Discussion started by: arjun_arippa
1 Replies

7. Shell Programming and Scripting

Delete blank lines, if blank lines are more than one using shell

Hi, Consider a file named "testfile" The contents of file are as below first line added for test second line added for test third line added for test fourth line added for test fifth line added for test (5 Replies)
Discussion started by: anil8103
5 Replies

8. 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

9. UNIX for Dummies Questions & Answers

How to count lines - ignoring blank lines and commented lines

What is the command to count lines in a files, but ignore blank lines and commented lines? I have a file with 4 sections in it, and I want each section to be counted, not including the blank lines and comments... and then totalled at the end. Here is an example of what I would like my... (6 Replies)
Discussion started by: kthatch
6 Replies

10. Solaris

finding & replacing blank rows/spaces in a file

Can anyone help me find and replace blank rows in a file with a numeric value (ie blankrow=someTxtOrNumValue), the file is over 500,000 rows long so it would need to be the quickest way as I'll need to do this for multiple files...I would be greatfull for any suggestions....thanks sample file:... (2 Replies)
Discussion started by: Gerry405
2 Replies
Login or Register to Ask a Question