Hi Everyone,
Long time lurker here. I have a project of bringing every one of our data centers to a newly enforced company standard. Standard naming conventions, domain migrations, etc. So, the people who are setting the standards are providing me with a CSV file. Column 1 has the old value, Column 2 has the new value. It looks like this example I pulled off the Internet:
President ,Home State
George Washington,Virginia
John Adams,Massachusetts
Thomas Jefferson,Virginia
James Madison,Virginia
James Monroe,Virginia
John Quincy Adams,Massachusetts
Andrew Jackson,Tennessee
Martin Van Buren,New York
William Henry Harrison,Ohio
John Tyler,Virginia
James K. Polk,Tennessee
Zachary Taylor,Louisiana
Millard Fillmore,New York
Franklin Pierce,New Hampshire
James Buchanan,Pennsylvania
Abraham Lincoln,Illinois
Andrew Johnson,Tennessee
Ulysses S. Grant,Ohio
Rutherford B. Hayes,Ohio
James A. Garfield,Ohio
Chester A. Arthur,New York
Grover Cleveland,New York
Benjamin Harrison,Indiana
Grover Cleveland (2nd term),New York
William McKinley,Ohio
Theodore Roosevelt,New York
William Howard Taft,Ohio
Woodrow Wilson,New Jersey
Warren G. Harding,Ohio
Calvin Coolidge,Massachusetts
Herbert Hoover,Iowa
Franklin D. Roosevelt,New York
Harry S. Truman,Missouri
Dwight D. Eisenhower,Texas
John F. Kennedy,Massachusetts
Lyndon B. Johnson,Texas
Richard Nixon,California
Gerald Ford,Michigan
Jimmy Carter,Georgia
Ronald Reagan,California
George H. W. Bush,Texas
Bill Clinton,Arkansas
George W. Bush,Texas
Barack Obama,Illinois
I am using awk to parse through and find the desired value of column one and then have it print the value right behind it. Here is my script but I cannot for the life of me to get one variable to output properly.
#!/bin/bash
# generate array of old file/folder/etc names
fileList=`commands to build array of data` # for arguments sake the presidents CSV file printed above
oldFile="/path/to/my/file_list.txt" # source of text file with old and new values
# loop through fileList and move folders or files
for i in ${fileList} ; do
newFile=$(/usr/bin/awk -F, '/${i}/ { print $2;exit }' ${oldFile})
if [[ `/usr/bin/awk -F, '/${i}/ { print $2;exit }' ${oldFile}` == ${newFile} ]]
then /bin/echo "${i} needs to be moved to ${newFile}"
/bin/echo "bunch of commands to rename folders"
else /bin/echo "${i} does not have a match"
fi
done
exit 0
Sorry for being really vague but trying to get a proof of concept here with out giving out any confidential information that may or may not be on the actual real scripts I am writing. Basically, it seems to work but when I run the script via bash -x /path/to/script the newFile never outputs right at all.