find files with 1 single row - UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find files with 1 single row - UNIX
# 8  
Old 03-22-2017
How about this? I added the redirects to filter out the errors on files that I could not read.
You can leave that in or take it out. I also chopped off the line count, word count character count.
I added the second part to remove the files. I have not tested the code for the remove.
But it should work.

Code:
# to display the files
for line in `find * -type f`
do
   if [ `wc -l $line | cut -d" " -f1` = 1 ]
   then
      echo "$line"
   fi
done

# to remove the files
for line in `find * -type f`
do
   if [ `wc -l $line | cut -d" " -f1` = 1 ]
   then
      rm -vi "$line"
   fi
done


Last edited by gandolf989; 03-22-2017 at 05:37 PM..
# 9  
Old 03-22-2017
If it is in a single directory, in pure shell, try:
Code:
for i in *
do
  if [ -f "$i" ] && read && ! read; then
    echo "$i"
  fi < "$i"
done

This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Splitting single row into multiple rows based on for every 10 digits of last field of the row

Hi ALL, We have requirement in a file, i have multiple rows. Example below: Input file rows 01,1,102319,0,0,70,26,U,1,331,000000113200000011920000001212 01,1,102319,0,1,80,20,U,1,241,00000059420000006021 I need my output file should be as mentioned below. Last field should split for... (4 Replies)
Discussion started by: kotra
4 Replies

2. Shell Programming and Scripting

Create multiple files from single file based on row separator

Hello , Can anyone please help me to solve the below - Input.txt source table abc col1 char col2 number source table bcd col1 date col2 char output should be 2 files based on the row separator "source table" abc.txt col1 char (6 Replies)
Discussion started by: Pratik4891
6 Replies

3. UNIX for Dummies Questions & Answers

How to find position of blank row in UNIX?

Hi I have file "emp.txt"like below 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. (5 Replies)
Discussion started by: rock_01
5 Replies

4. Shell Programming and Scripting

how to find first files in a directory and combine them as a single file?

i have below list of files in a directory. /root/admin/files/file1.txt /root/admin/files/file2.txt /root/admin/files/file3.txt /root/admin/files/pattern.txt /root/admin/files/server.txt i need combine the above text files in the below sequence, file1.txt, pattern.txt,server.txt =>... (8 Replies)
Discussion started by: vel4ever
8 Replies

5. Shell Programming and Scripting

Find all the files under a specific directory and zip them into a single file.

Hi, Is there a way to find all the files from a specific location and then zip them into a single file, even if they are in multiple directories? (3 Replies)
Discussion started by: rudoraj
3 Replies

6. Shell Programming and Scripting

Subtracting each row from the first row in a single column file using awk

Hi Friends, I have a single column data like below. 1 2 3 4 5 I need the output like below. 0 1 2 3 4 where each row (including first row) subtracting from first row and the result should print below like the way shown in output file. Thanks Sid (11 Replies)
Discussion started by: ks_reddy
11 Replies

7. Shell Programming and Scripting

Converting Multiple rows to Single Row using unix commands

Can somebody help me in solving this.. Input data is like 0 A 1 B 2 C 3 D 0 A1 1 B1 2 C1 3 D1 0 A2 1 B2 2 C2 3 D2 Output should be like A B C D A1 B1 C1 D1 A2 B2 C2 D2 (7 Replies)
Discussion started by: Mahantesh Patil
7 Replies

8. Shell Programming and Scripting

Combile two files - report should be in single row

Dear sir I am having a file x.lst having abcd andother file y.lst having efgh I should get report file having the result in a single row as abcdefgh pls help (3 Replies)
Discussion started by: suryanarayana
3 Replies

9. Shell Programming and Scripting

Single/Multiple Line with Special characters - Find & Replace in Unix Script

Hi, I am creating a script to do a find and replace single/multiple lines in a file with any number of lines. I have written a logic in a script that reads a reference file say "findrep" and populates two variables $FIND and $REPLACE print $FIND gives Hi How r $u Rahul() Note:... (0 Replies)
Discussion started by: r_sarnayak
0 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