How to find position of blank row in UNIX?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to find position of blank row in UNIX?
# 1  
Old 02-26-2015
How to find position of blank row in UNIX?

Hi

I have file "emp.txt"like below

Code:
Emp Id    Name
123          aa
123          bb

223          cc
233         dd

334        ee

Please help me to know that the position of the blank row.

Last edited by Scrutinizer; 02-26-2015 at 03:57 AM.. Reason: code tags
# 2  
Old 02-26-2015
Hello rock_01,

Welcome to forum, please use code tags as per forum rules.
Following may help you in same.
Code:
awk 'BEGIN{A=1} {if($0 ~ /^$/){print A;A++;next}} {A++};'  Input_file
OR
awk '($0 ~ /^$/){print NR}'  Input_file

Output will be as follows in both above commands.
Code:
4
7

Thanks,
R. Singh

Last edited by RavinderSingh13; 02-26-2015 at 03:35 AM.. Reason: Added one more solution
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 02-26-2015
Hi Ravi,

Thanks,
But I am not getting the output.

Code:
var/www$ cat birth.txt
Emp Id Name
123 aa
123 bb

223 cc
233 dd

334 ee

I tried with both the command but didn't got the output.
Please check below:-

Code:
:/var/www$ awk '($0 ~ /^$/){print NR}' birth.txt
:/var/www$ awk 'BEGIN{A=1} {if($0 ~ /^$/){print A;A++;next}} {A++};'  birth.txt
:/var/www$


Last edited by Scrutinizer; 02-26-2015 at 03:58 AM..
# 4  
Old 02-26-2015
Try:
Code:
awk '!NF{print NR}' file

This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 02-27-2015
Is there any other way to do this. I am still not getting the proper output
# 6  
Old 02-27-2015
Hello rock_01,

Could you please run following command to your input file as follows, to make sure there are
NO carriage returns in your file ^M charcters.
Code:
cat -v Input_file

If you are not seeing the carriage chars then kindly do show us the error you are getting
while executing previous solutions with your input file please.

Thanks,
R. Singh
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Column to row and position data in a text file

Hi everyone.. I have a list of values in a file... a, b, c, 1, 2, 3, aaaa, bbbbb, I am interested in converting this column to a row.. "text",aaaa, bbbb a,1 (7 Replies)
Discussion started by: manihi
7 Replies

2. Shell Programming and Scripting

find files with 1 single row - UNIX

Hi, How could Find files with 1 single row in unix I need delete files with 1 single row (8 Replies)
Discussion started by: Marlboro
8 Replies

3. Shell Programming and Scripting

Search for a string at a particular position and replace with blank based on position

Hi, I have a file with multiple lines(fixed width dat file). I want to search for '02' in the positions 45-46 and if available, in that lines, I need to replace value in position 359 with blank. As I am new to unix, I am not able to figure out how to do this. Can you please help me to achieve... (9 Replies)
Discussion started by: Pradhikshan
9 Replies

4. Shell Programming and Scripting

How to search for blank fields in a text file from a certain position?

Sample txt file : OK00001111112| OK00003443434|skjdaskldj OK32812983918|asidisoado OK00000000001| ZM02910291029|sldkjaslkjdasldjk what would be the shell script to figure out the blank space (if any) after the pipe sign? (4 Replies)
Discussion started by: chatwithsaurav
4 Replies

5. Shell Programming and Scripting

Copying down first row in to all the below blank rows in a .csv file

Hi All, I have many of files(.csv) of the format given below. Date,Name,Location 04/02/2012,A,India ,B,China ,C,USA Like this I have 1000's of rows and many columns in all my files. I need a shell script to copy down the Date(in this example column1) to the next 2 rows below(in the... (8 Replies)
Discussion started by: ks_reddy
8 Replies

6. Shell Programming and Scripting

Awk Line/Row Position

Hi guys. I'd just like to know if its possible to change the actual line/row position in awk while its busy processing a file. In other words, is it possible to jump from line 10, back up to line 5 and continue processing line-by-line from then onwards? or is the way around this to add all lines... (3 Replies)
Discussion started by: going_grey
3 Replies

7. Shell Programming and Scripting

Unix help to find blank lines in a file and print numbers on that line

Hi, I would like to know how to solve one of my problems using expert unix commands. I have a file with occasional blank lines; for example; dertu frthu fghtu frtty frtgy frgtui frgtu ghrye frhutp frjuf I need to edit the file so that the file looks like this; (10 Replies)
Discussion started by: Lucky Ali
10 Replies

8. UNIX for Dummies Questions & Answers

find if a position is between a given start and end position

Hi, I am a newbie in unix programming so maybe this is a simple question. I would like to know how can I make a script that outputs only the values that are not between any given start and end positions Example file1: 2 30 40 80 82 100 file2: ID1 1 ID2 35 ID3 80 ID4 81 ID6... (9 Replies)
Discussion started by: fadista
9 Replies

9. Shell Programming and Scripting

how to find a position and print some string in the next and same position

I need a script for... how to find a position of column data and print some string in the next line and same position position should find based on *HEADER8* in text for ex: ord123 abs 123 987HEADER89 test234 ord124 abc 124 987HEADER88 test235 ... (1 Reply)
Discussion started by: naveenkcl
1 Replies

10. UNIX for Advanced & Expert Users

How to find n'th row from UNIX file?

Hello Gurus, I am new to this forum and I have a BASIC knowlege in UNIX commands. I have a data file which contains 1 billion records, how to find 5678th row and put this rows into a new file? Can anybody please give the command how to do this? (3 Replies)
Discussion started by: nvkuriseti
3 Replies
Login or Register to Ask a Question