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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:54:04+00:00 2026-05-19T13:54:04+00:00

So I am going to post a question about shell scripting again. Problem Definition:

  • 0

So I am going to post a question about shell scripting again.

Problem Definition: For all files under a dir, ex.:

  • A_anything.txt, B_anything.txt, ……

I want to execute a script, say ‘CMD’, on each of them, with the output files named like:

  • A_result.txt, B_result.txt, ……

In addition, at the first line of these output file, I want to have the file name of the original one.

The ‘find -exec’ util seems to me unable to extract part of the file name.

Does someone know a solution to this problem, by any means(shell, python, find,etc)? Thank you!

  • 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-19T13:54:04+00:00Added an answer on May 19, 2026 at 1:54 pm
    cd /directory
    for file in *.txt ; do
        newfilename=`echo "$file"|sed 's/\(.\+\)_.*/\1_result.txt/`
        echo "$file" > "$newfilename" 
        your-command $file >> "$newfilename"
    done
    

    HTH

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

Sidebar

Related Questions

So these 2 files I am going to post are each in my DataBase
I have post a question before about my company requirement and I have got
and thanks first of all for looking at my post. My question today is
I was going to post a question, but figured it out ahead of time
Before going live with my website, i made some thoughts about security: This question
Starting a new thread... about same question.. I have tried all I am getting
I was going to post this on Database Administrators, but as it is slightly
This is going to be a long post and just for fun, so if
A few days ago, I posted this question and this question asking about how
Original question has been answered. Update addresses related question raised in comments. Original post:

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.