Shell command bundle

1 minute read

Published:

Shell magic eases tasks sometimes

find . -type f -not -name ‘restart’ | xargs -I {} sed -i ‘’ -e ‘s/.checkpointFileNumber./checkpointFileNumber = 0/g’ {}

This command is using the “find” command to search for files in the current directory that are not named “restart”. The “-type f” flag indicates that only files should be searched for, and the “-not -name ‘restart’” flag excludes files that have “restart” in the name. The search results are passed as arguments to the “xargs” command, which runs the “sed” command on each file found. The “sed” command is using the “-i’’” flag to edit the files in-place and the “-e” flag to specify the script which is replacing the line that match the regular expression “.checkpointFileNumber.” with the line “checkpointFileNumber = 0”. This command effectively searches for all files that do not contain “restart” in the name and changes the value of “checkpointFileNumber” to 0 in each file.

grep -l -R plotfileIntervalTime . | xargs -I {} sed -i ‘’ -e ‘s/.plotfileIntervalTime./plotfileIntervalTime = 0/g’ {}

This command is using the “grep” command to search recursively through the current directory (indicated by the “.” argument) for files that contain the string “plotfileIntervalTime”. The “-l” flag tells grep to show only the name of files that contain the search string, and the “-R” flag tells grep to search recursively through the directory. The search results are passed as arguments to the “xargs” command, which runs the “sed” command on each file found. The “sed” command is using the “-i’’” flag to edit the files in-place and the “-e” flag to specify the script which is replacing the line that match the regular expression “.plotfileIntervalTime.” with the line “plotfileIntervalTime = 0”. This command effectively searches recursively through the current directory for all files containing the string “plotfileIntervalTime” and replaces the line with “plotfileIntervalTime = 0”