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
# 1  
Old 03-22-2017
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
# 2  
Old 03-22-2017
Is this a homework assignment? Homework and coursework questions can only be posted in the Homework & Coursework forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

If you did not post homework, please explain the company you work for and the nature of the problem you are working on. Tell us what operating system and shell you're using. Tell us where the files you want to remove are located. Tell us whether the files you want to remove are all in a single directory or are located in a file hierarchy. It would seem that some combination of wc and rm probably with find or a shell for loop should provide what you need.
# 3  
Old 03-22-2017
It's for my job,For security reasons the company could not say, but I work on a migration of information,Find files with 1 single row in unix,
The files with 1 single row do not work, because they only have the header, I wanted to erase them
# 4  
Old 03-22-2017
Assuming that the path of the file to investigate is stored on variable file, the naive approach to test, whether it is a candidate for deletion, would be (in, say, bash or zsh)

Code:
if [[ $(wc -l <$file) == 1 ]]
then
    ....
fi

Alternatively, you could also write in this particular case
Code:
if [[ $(wc -l <$file) -eq 1 ]]

or
Code:
if (( $(wc -l <$file) == 1 ))

The problem is how you want to treat files which have some content, but no terminating newline, and files which are completely empty. For them, *wc -l* would report zero. Depending on whether or not you want to delete them too, you would have to adapt the condition accordingly.

Last edited by rovf; 03-22-2017 at 05:09 AM.. Reason: Improving explanation
This User Gave Thanks to rovf For This Post:
# 5  
Old 03-22-2017
Would this thread help?
# 6  
Old 03-22-2017
I only want to delete the files of 1 single line, the other files if they are empty or with information for me is ok, I do not have files without line termination.
# 7  
Old 03-22-2017
So - how would you adapt the hint given?
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