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

  • Home
  • SEARCH
  • 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 8090743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:49:24+00:00 2026-06-05T19:49:24+00:00

I have never programed in bash before. I am reading all the files that

  • 0

I have never programed in bash before.
I am reading all the files that are in a directory, then I need to look into their names and check if the have R1 or R2, depending on that I need concatenate all files that have R1 in the same and all files that have R2 in the name.
So as a final output I would like to have something like:

String 1 = file1_R1.gz file2_R1.gz file3_R1.gz…

String 2 = file1_R2.gz file2_R2.gz file3_R2.gz…

how can I do that? the only code that I have so far is:

#!/bin/bash

list=$(echo *.gz)

strR1="R1"
strR2="R2"

if [ "$list" = "*.gz" ] ; then list=""; fi

for str in $list
do
    if echo "$strR1"  | grep -q "$str"; then
         echo "str";
else 
echo "no file";
fi

done

I can read all the files in the directory but when I do the if I cannot find any file with R1, and I know that there are at least 4 files with R1 in the name.

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-06-05T19:49:26+00:00Added an answer on June 5, 2026 at 7:49 pm

    Why write a loop to do the filtering wildcards will already do for you? (You’re using the same thing to filter *.gz already.)

    files1=`echo *R1*.gz`
    files2=`echo *R2*.gz`
    

    Since you said you want to concatenate all those files, that would then be

    zcat *R1.gz > result_R1
    zcat *R2.gz > result_R2
    

    or something like that.

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

Sidebar

Related Questions

I have a directory that continually fills up with artefact files. Many different programs
I have never programed in Python before, so excuse my code. I have this
I have never programmed in visual basic before and my boss just told me
I have program that has a variable that should never change. However, somehow, it
I have never made a blog before. I am proficient with html and css.
I've never programmed in java or eclipse before, although I have used c# and
I need to access Active Directory to get information about groups that customers belong
I have never programmed anything in php before and haven't touched html in 10
1st of all: I'm not a programmer, never learnt programming/algorithms. Actually I have to
I have never programmed web sites. I know that I can create web sites

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.