[Solved] Linux ‘cut’ command line and replace

This should do the trick: #!/bin/bash INPUT=”$@” SIZE=${#INPUT} for ((i=0; i < ${SIZE}; i++)); do echo “${INPUT}” INPUT=”${INPUT:0:${i}} ${INPUT:$((i+1)):${SIZE}}” #INPUT=”$(echo “$INPUT” | sed “s/^\(.\{${i}\}\)./\1 /”)” done I added a sed option in the comment, although it creates a sub-process when you don’t really have to. 0 solved Linux ‘cut’ command line and replace

[Solved] Bash script to download data from url

You have two bits here. One is to schedule a cron job and the other is to get the file & save it. Steps : Open the terminal & run crontab -e minute(0-59) hour(0-23) day(1-31) month(1-12) weekday(0-6) command In place of minute, hour, day, month & weekday. Also provide the command to run. The command … Read more

[Solved] sed/regex to change only few of multiple matching characters

with sed based on position $ echo abc-def-ghi-2017-10-31 | sed ‘s/-/./4g’ abc-def-ghi-2017.10.31 based on surrounding chars $ echo abc-def-ghi-2017-10-31 | sed -r ‘s/([0-9])-([0-9])/\1.\2/g’ abc-def-ghi-2017.10.31 based on the position from the end of string $ echo abc-def-ghi-2017-10-31 | rev | sed ‘s/-/:/g; s/:/-/3g’ | rev abc-def-ghi-2017:10:31 2 solved sed/regex to change only few of multiple matching … Read more

[Solved] Splitting comma set files

This might work for you (GNU sed): sed -r ‘s/^(.*\|.*\|)([^,]*),([^|]*)(\|.*\|.*\|)([^,]*),([^|]*)(.*)/\1\2\4\5\7\n\1\3\4\6\7/;P;D’ file Iteratively split the current line into pieces, building two lines separated by a newline. The first line contains the head of the 3rd and 6th fields, the second line contain the tails of the 3rd and 6th lines. Print then delete the first of … Read more

[Solved] move all folders modified after to new folder [closed]

import os from shutil import move from time import time def mins_since_mod(fname): “””Return time from last modification in minutes””” return (time() – os.path.getmtime(fname)) / 60 PARENT_DIR = ‘/some/directory’ MOVE_DIR = ‘/where/to/move’ # Loop over files in PARENT_DIR for fname in os.listdir(PARENT_DIR): # If the file is a directory and was modified in last 15 minutes … Read more

[Solved] How do I remove all lines starting from the beginning until I reach a certain pattern, except from the last one [closed]

The way to do this is by using awk as you already suggested. As you say, you want to print the lines starting from the first occurrence where you have 3 fields, this can easily be done by setting a print flag (let’s call it p)’ awk ‘(NF==3){p=1};p’ file This will print everything starting from … Read more

[Solved] Making a terminal executable file that changes the date on your Mac [closed]

You can change the date of the mac using the following command from the terminal. date -u {month}{day}{hour}{minute}{year} Replaced bracket with a two digit number. To set, October 16th 2020 21:16 would become the following command: date 1016211620 Or you can create apple script to do it: set ntpdPID to do shell script “systemsetup -getusingnetworktime; … Read more

[Solved] Rearrange and delete fields with sed

You can use the following sed command, let me know if you need additional explanations about it: sed -E -i.bak ‘s/^([^\s]*)\s+([^,]*),[^,]*,\s*([^\s]*)\s+([^\s]*)\s*$/\4:\2:\1:\3/g’ test_add_file.in; TESTED on: In a nutshell, you are define a regex that sed will use to look in your text file to fetch the required patterns, then you use backreferences to reuse the actual … Read more