QC

Qwiklabs Assessment: Editing Files Using Substrings - coursera

Editing Files using Substrings

Your coworker Jane Doe currently has the username "jane" but she needs to it to "jdoe" to comply with your company's naming policy. This username change has already been done. However, some files that were named with Jane's previous username "jane" haven't been updated. For example, "jane_profile_07272018.doc" needs to be updated to "jdoe_profile_07272018.doc".

findJane.sh

#!/bin/bash
> oldFiles.txt
files=$(grep " jane " ../data/list.txt | cut -d' ' -f3)
for f in $files; do
   echo $f>>oldFiles.txt
done


changeJane.py

#!/usr/bin/env python3
import sys
import subprocess

f  = open(sys.argv[1], 'r')
path = '/home/<your-student-id-from-quicklab>'
for line in f.readlines():
  old = line.strip()
  new = old.replace('jane', 'jdoe')
  subprocess.run(["mv", path + str(old) ,path + str(new)])

f.close()

Post a Comment

Previous Post Next Post