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 6909969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:45:21+00:00 2026-05-27T08:45:21+00:00

I want to parse and filter a file that looks like this: @@1 Row

  • 0

I want to parse and filter a file that looks like this:

@@1 Row one. 
@@2 Row two.

I have been able to do the filtering of the rows with the following code:

(defn parse-text-cms [sel-row]
  (let [f_data  (st/split  #"@@" (slurp "cms/tb_cms.txt"))] 
  ;(prn (map #(take 1 %) f_data))))
  (filter  #(= (first (take 1 %)) sel-row) f_data)))

However, this codes gives me (if sel-row=1):

1 Row one.

I would like to chop off that 1 and the space after, so to have:

Row one.

I think there is some sequence magic to do this. I just can’t come up with an elegant solution.

  • 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-05-27T08:45:22+00:00Added an answer on May 27, 2026 at 8:45 am

    I would define the function the following way:

    (defn parse-text-cms [sel-row]
      (with-open [input (clojure.java.io/reader "cms/tb_cms.txt")]
        (first
         (for [[_ number line] (map (partial re-find #"@@(\d)+\s+(.*)")
                                    (line-seq input))
               :when (= number (str sel-row))]
           line))))
    

    The combination of line-seq and reader gives me a sequence of lines from the input file. with-open ensures that the file is properly closed when I’m done. I apply a regex to each line that looks for @@ followed by a number and some spaces.

    re-find returns a vector with three items:

    • the whole matched line
    • the number (the first group in the regex)
    • the rest of the line (the second group in the regex)

    I bind these to number and line using destructuring in a for statement (I’m not interested in the whole matched line, so I ignore that). I filter for the selected sel-row using :when and yield only the (rest of the) line.

    Since I only expect one match in the file, I return just the first item from the sequence built by for. Because of the laziness of for, map and line-seq, this also stops reading of the file after the item is found.

    If you do a lot of lookups for rows, I would suggest loading the whole file into memory instead of reading it every time, though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an intent filter that looks like so: <activity android:name=com.test.Call android:label=@string/makeCall > <intent-filter>
I have an XML file in the drawable-folder. I want parse the XML-file using
I want to parse a config file sorta thing, like so: [KEY:Value] [SUBKEY:SubValue] Now
i have been working on this text extraction project of various file extensions, but
I have an NSArray that I want to filter out certain objects using an
I want to parse a filter string similar to the following: ((Field1 = 'red')
I want to parse .csv file which is in public folder, I've tried /../
I want to parse an Apache access.log file with a python program in a
I'm using YQL to parse some web feeds, this one in particular. SELECT *
I'm trying to filter an XML file using XPath. The XPath that I'm using

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.