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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:30:40+00:00 2026-05-25T18:30:40+00:00

i need a bash script for mac osx working in this way: ./script.sh *

  • 0

i need a bash script for mac osx working in this way:

./script.sh * folder/to/files/ 
#
# or #
#
./script.sh xx folder/to/files/

This script

  • read a list of files
  • open each file and read each lines
  • if lines ended with the same letters (‘*‘ mode) or with custom letters (‘xx‘) then
    remove line and RE-SAVE file
  • backup original file

My first approach to do this:

#!/bin/bash

# ck init params
if [ $# -le 0 ]
then
  echo "Usage: $0 <letters>"
  exit 0
fi

# list files in current dir
list=`ls BRUTE*` 
for i in $list 
do 

  # prepare regex    
  case $1 in
       "*") REGEXP="^.*(.)\1+$";;
       *) REGEXP="^.*[$1]$";;
  esac    
  FILE=$i

  # backup file
  cp $FILE $FILE.bak

  # removing line with same letters
  sed -Ee "s/$REGEXP//g" -i '' $FILE
  cat $FILE | grep -v "^$"

done

exit 0

But it doesn’t work as i want….

What’s wrong?
How can i fix this script?


Example:

$cat BRUTE02.dat BRUTE03.dat
aa
ab
ac
ad
ee
ef
ff
hhh
$

If i use ‘*‘ i want all files that ended with same letters to be clean.
If i use ‘ff‘ i want all files that ended with ‘ff‘ to be clean.


Ah, it’s on Mac OSx. Remember that sed is a little different from classical linux sed.

man sed

 sed [-Ealn] command [file ...]
 sed [-Ealn] [-e command] [-f command_file] [-i extension] [file

…]

DESCRIPTION
The sed utility reads the specified files, or the standard input
if no files are specified, modifying the input as specified by a list
of commands. The
input is then written to the standard output.

 A single command may be specified as the first argument to sed. 

Multiple commands may be specified by using the -e or -f options. All
commands are applied
to the input in the order they are specified regardless of their
origin.

 The following options are available:

 -E      Interpret regular expressions as extended (modern)

regular expressions rather than basic regular expressions (BRE’s).
The re_format(7) manual page
fully describes both formats.

 -a      The files listed as parameters for the ``w'' functions

are created (or truncated) before any processing begins, by default.
The -a option causes
sed to delay opening each file until a command containing
the related “w” function is applied to a line of input.

 -e command
         Append the editing commands specified by the command

argument to the list of commands.

 -f command_file
         Append the editing commands found in the file

command_file to the list of commands. The editing commands should
each be listed on a separate line.

 -i extension
         Edit files in-place, saving backups with the specified

extension. If a zero-length extension is given, no backup will be
saved. It is not recom-
mended to give a zero-length extension when in-place
editing files, as you risk corruption or partial content in situations
where disk space is
exhausted, etc.

 -l      Make output line buffered.

 -n      By default, each line of input is echoed to the standard

output after all of the commands have been applied to it. The -n
option suppresses this
behavior.

 The form of a sed command is as follows:

       [address[,address]]function[arguments]

 Whitespace may be inserted before the first address and the

function portions of the command.

 Normally, sed cyclically copies a line of input, not including

its terminating newline character, into a pattern space, (unless there
is something left
after a “D” function), applies all of the commands with
addresses that select that pattern space, copies the pattern space to
the standard output, append-
ing a newline, and deletes the pattern space.

 Some of the functions use a hold space to save all or part of the

pattern space for subsequent retrieval.

anything else?
it’s clear my problem?

thanks.

  • 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-25T18:30:41+00:00Added an answer on May 25, 2026 at 6:30 pm

    This is the problem!

    grep '\(.\)\1[^\r\n]$' *
    

    on MAC OSX, ( ) { }, etc… must be quoted!!!

    Solved, thanks.

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

Sidebar

Related Questions

I am working on a bash script where I need to conditionally execute some
I am working in a bash script where I need to analyze the output
I need to read a value from the terminal in a bash script. I
I'm writing a Bash script. I need the current working directory to always be
I need to replace this line through a Bash script: $config['language'] = english; With
I need to create a bash script that will work on a mac. It
I need a bash script that goes trough a text file, finds lines starting
I need a bash script to format a text file. It must add a
I need your help with a short bash script. I have a folder, which
I need to read some configuration data into environment variables in a bash script.

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.