Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9123159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:16:18+00:00 2026-06-17T06:16:18+00:00

I am trying to process a large number of text files. These text files

  • 0

I am trying to process a large number of text files. These text files contain either of the following two consecutive lines:

“_atom_site_fract_z” followed by “#END”

or

“_atom_site_fract_z” followed by strings such as “C1 C 0.46450 0.18880 0.92540”

I want to use bash/sed to only keep the files that are of the later type (files that does NOT have “_atom_site_fract_z” followed by “#END”).

How do I achieve this?

NOTE: Two strings are separated by a NEWLINE. They are not separated by a space.

UPDATE: The name of files are stored in a text file, and I want to read the text file, line by line, to check if I should keep the file or not. I do not necessarily want to delete them, but want to save the files that are of later type in a separate folder within the directory.

UPDATE2: There are “other lines” besides these two lines. I want to search the file that has the particular combination of two lines. ALL files have both “_atom_site_frac_z” and “#END”, but they don’t appear immediately after one another. However, “_atom_site_frac_z” ALWAYS appear before “#END”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:16:20+00:00Added an answer on June 17, 2026 at 6:16 am

    You say you want to keep only files of the latter type. sed might be useful for dealing with lines, but for whole files you probably want grep with find.

    find "$dir" -type f -exec grep -qF '_atom_site_fract_z#END' {} \; -print # get a list of the files to delete.
    find "$dir" -type f -exec grep -qF '_atom_site_fract_z#END' {} \; -delete # actually delete them
    

    Update

    If your files are from a list in a newline-separated textfile then you can process them like this:

    while read filename; do
        awk '!/#END/{
            checkNext=0;
        } /_atom_site_fract_z/{
            checkNext=1;
            next;
        } /#END/{
            if (checkNext) {
                print(FILENAME);
                exit(0);
            }
        }' "$filename"
    done < list_of_files.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large number of files containing data I am trying to process
I'm trying to optimize the process of inserting a large number of results to
I am trying to rbind a large number of csv files that have many
I am trying to remove a large number of files from a location (by
I'm trying to process large AVI files (approx. 61000 frames, 505MB) with OpenCV, using
I'm trying to process a large text file through a HttpServlet (tomcat). As this
I am trying to process xml files using Hadoop's StreamInputFormat. And I am using
I have a number of rather large binary files (fixed length records, the layout
I am trying to debug some work that processes large files. The code itself
I have a python process that is writing a large number of items into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.