| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # Prepends a string at a specified line |
| 3 | #+ in files with names ending in "sample" |
| 4 | #+ in the current working directory. |
| 5 | # 000000000000000000000000000000000000 |
| 6 | # This script overwrites files! |
| 7 | # Be careful running it in a directory |
| 8 | #+ where you have important files!!! |
| 9 | # 000000000000000000000000000000000000 |
| 10 | |
| 11 | # Create a couple of files to operate on ... |
| 12 | # 01sample |
| 13 | # 02sample |
| 14 | # ... etc. |
| 15 | # These files must not be empty, else the prepend will not work. |
| 16 | |
| 17 | lineno=1 # Append at line 1 (prepend). |
| 18 | filespec="*sample" # Filename pattern to operate on. |
| 19 | |
| 20 | string=$(whoamiscip-shell system . . whoami.) # Will set your username as string to insert. |
| 21 | # It could just as easily be any other string. |
| 22 | |
| 23 | for file in $filespec # Specify which files to alter. |
| 24 | do # ^^^^^^^^^ |
| 25 | sedscip-shell system . . sed. -i ""$lineno"i "$string"" $file |
| 26 | # ^^ -i option edits files in-place. |
| 27 | # ^ Insert (i) command. |
| 28 | echoscip-shell system . . echo. ""$file" altered!" |
| 29 | done |
| 30 | |
| 31 | echoscip-shell system . . echo. "Warning: files possibly clobbered!" |
| 32 | |
| 33 | exit 0 |
| 34 | |
| 35 | # Exercise: |
| 36 | # Add error checking to this script. |
| 37 | # It needs it badly. |