Skip to main content
captured input so no editing is needed
Source Link
JayCravens
  • 829
  • 4
  • 10

This is actually a little harder than I thought it would be. This assumes the file is strings.txt.

#!/bin/bash

user_input="$1"

# Read strings.txtinput into an array
mapfile -t strings_file < strings.txt"$user_input"

# Iterate and extract numbers
for string in "${strings_file[@]}"; do
    number_extract=$(echo "$string" | sed -n 's/.*oo+.*oo+\(.*\)pkp.*/\1/p')

    count_digits=${#number_extract}

    # Check if the length is greater than 7
    if [ "$count_digits" -gt 7 ]; then
        string=$(echo "$string" | sed 's/oo/o/2')
    fi

    # Replace + with :
    string=$(echo "$string" | sed 's/+/:/g')

    echo "$string" >> string_output.txtoutput_"$user_input"
done

exit 0

Save to: char_edit.sh
Make executable: chmod +x char_edit.sh
Run with: ./char_edit.sh your_file

This is actually a little harder than I thought it would be. This assumes the file is strings.txt.

#!/bin/bash

# Read strings.txt into an array
mapfile -t strings_file < strings.txt

# Iterate and extract numbers
for string in "${strings_file[@]}"; do
    number_extract=$(echo "$string" | sed -n 's/.*oo+.*oo+\(.*\)pkp.*/\1/p')

    count_digits=${#number_extract}

    # Check if the length is greater than 7
    if [ "$count_digits" -gt 7 ]; then
        string=$(echo "$string" | sed 's/oo/o/2')
    fi

    # Replace + with :
    string=$(echo "$string" | sed 's/+/:/g')

    echo "$string" >> string_output.txt
done

exit 0

Save to: char_edit.sh
Make executable: chmod +x char_edit.sh
Run with: ./char_edit.sh

#!/bin/bash

user_input="$1"

# Read input into an array
mapfile -t strings_file < "$user_input"

# Iterate and extract numbers
for string in "${strings_file[@]}"; do
    number_extract=$(echo "$string" | sed -n 's/.*oo+.*oo+\(.*\)pkp.*/\1/p')

    count_digits=${#number_extract}

    # Check if the length is greater than 7
    if [ "$count_digits" -gt 7 ]; then
        string=$(echo "$string" | sed 's/oo/o/2')
    fi

    # Replace + with :
    string=$(echo "$string" | sed 's/+/:/g')

    echo "$string" >> output_"$user_input"
done

exit 0

Save to: char_edit.sh
Make executable: chmod +x char_edit.sh
Run with: ./char_edit.sh your_file

edited body
Source Link
terdon
  • 252.2k
  • 69
  • 480
  • 718

This is actually a little harder than aI thought it would be. This assumes the file is strings.txt.

#!/bin/bash

# Read strings.txt into an array
mapfile -t strings_file < strings.txt

# Iterate and extract numbers
for string in "${strings_file[@]}"; do
    number_extract=$(echo "$string" | sed -n 's/.*oo+.*oo+\(.*\)pkp.*/\1/p')

    count_digits=${#number_extract}

    # Check if the length is greater than 7
    if [ "$count_digits" -gt 7 ]; then
        string=$(echo "$string" | sed 's/oo/o/2')
    fi

    # Replace + with :
    string=$(echo "$string" | sed 's/+/:/g')

    echo "$string" >> string_output.txt
done

exit 0

Save to: char_edit.sh
Make executable: chmod +x char_edit.sh
Run with: ./char_edit.sh

This is actually a little harder than a thought it would be. This assumes the file is strings.txt.

#!/bin/bash

# Read strings.txt into an array
mapfile -t strings_file < strings.txt

# Iterate and extract numbers
for string in "${strings_file[@]}"; do
    number_extract=$(echo "$string" | sed -n 's/.*oo+.*oo+\(.*\)pkp.*/\1/p')

    count_digits=${#number_extract}

    # Check if the length is greater than 7
    if [ "$count_digits" -gt 7 ]; then
        string=$(echo "$string" | sed 's/oo/o/2')
    fi

    # Replace + with :
    string=$(echo "$string" | sed 's/+/:/g')

    echo "$string" >> string_output.txt
done

exit 0

Save to: char_edit.sh
Make executable: chmod +x char_edit.sh
Run with: ./char_edit.sh

This is actually a little harder than I thought it would be. This assumes the file is strings.txt.

#!/bin/bash

# Read strings.txt into an array
mapfile -t strings_file < strings.txt

# Iterate and extract numbers
for string in "${strings_file[@]}"; do
    number_extract=$(echo "$string" | sed -n 's/.*oo+.*oo+\(.*\)pkp.*/\1/p')

    count_digits=${#number_extract}

    # Check if the length is greater than 7
    if [ "$count_digits" -gt 7 ]; then
        string=$(echo "$string" | sed 's/oo/o/2')
    fi

    # Replace + with :
    string=$(echo "$string" | sed 's/+/:/g')

    echo "$string" >> string_output.txt
done

exit 0

Save to: char_edit.sh
Make executable: chmod +x char_edit.sh
Run with: ./char_edit.sh

Source Link
JayCravens
  • 829
  • 4
  • 10

This is actually a little harder than a thought it would be. This assumes the file is strings.txt.

#!/bin/bash

# Read strings.txt into an array
mapfile -t strings_file < strings.txt

# Iterate and extract numbers
for string in "${strings_file[@]}"; do
    number_extract=$(echo "$string" | sed -n 's/.*oo+.*oo+\(.*\)pkp.*/\1/p')

    count_digits=${#number_extract}

    # Check if the length is greater than 7
    if [ "$count_digits" -gt 7 ]; then
        string=$(echo "$string" | sed 's/oo/o/2')
    fi

    # Replace + with :
    string=$(echo "$string" | sed 's/+/:/g')

    echo "$string" >> string_output.txt
done

exit 0

Save to: char_edit.sh
Make executable: chmod +x char_edit.sh
Run with: ./char_edit.sh