Find Files and then convert them to Uppercase


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find Files and then convert them to Uppercase
# 8  
Old 04-19-2012
There we go, NAWK did the trick, you sir are awesome. Im guessing I just need to throw an MV in here somewhere and that should do the trick to rename?
# 9  
Old 04-19-2012
you could do:

Code:
#!/usr/bin/env bash
find ... | while IFS= read -r file; do
   upper=$(nawk ... <<< "$file")
   echo mv "$file" "$upper"
done

if that looks good, remove the echo
This User Gave Thanks to neutronscott For This Post:
# 10  
Old 04-19-2012
Thanks Neutronscott, Ill give that a shot right now.

---------- Post updated at 07:49 PM ---------- Previous update was at 07:46 PM ----------

You guys are awesome, that worked perfectly neutronscott, thank you both for the help!

---------- Post updated at 07:50 PM ---------- Previous update was at 07:49 PM ----------

Just for anyone's reference in the future who is searching: an example of this in its totality for Solaris 10 especially:

Code:
#!/usr/bin/env bash
find /path/to/search/dir -name '*.txt'| while IFS= read -r file; do
   upper=$(nawk -F"/" -v OFS="/" '{$NF=toupper($NF)} 1' <<< "$file")
   echo mv "$file" "$upper"
done

# 11  
Old 04-20-2012
In bash version 4 or above, you can perform this
Code:
for i in $(find /path/to/search/dir -name '*.txt'); do
     mv "${i}" "${i^^}"
done

# 12  
Old 04-20-2012
Being he has Solaris, I wouldn't assume he has anything higher than bash 2...

Also, that's a useless use of backticks. The loop can be rewritten far more safely as
Code:
find ... | while read LINE
do
...
done

This User Gave Thanks to Corona688 For This Post:
# 13  
Old 04-20-2012
Just for the record, the whole construct can be sped up by omitting the while loop:
Code:
find /path/to/dir -name "*.txt" -print | sed -e 's/^/"/' -e 's/$/"/' |  nawk -F/ '{orig=$0; $NF=toupper($NF); print "mv " orig " " $0}'  OFS=/

This will just print the commands; to run them, pipe it to sh:
Code:
find /path/to/dir -name "*.txt" -print | sed -e 's/^/"/' -e 's/$/"/' |  nawk -F/ '{orig=$0; $NF=toupper($NF); print "mv " orig " " $0}' OFS=/ | sh

The sed part inserts quotes around the filename.
This User Gave Thanks to mirni For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cannot find correct syntax to make file name uppercase letters

I have a file name : var=UsrAccChgRpt I want to make them upper case. Tried: $var | tr Error: tr: Invalid combination of options and Strings. Usage: tr | -ds | -s | -ds | -s ] String1 String2 tr { -d | -s | -d | -s } String1 Could you please help. I am using AIX... (2 Replies)
Discussion started by: digioleg54
2 Replies

2. Shell Programming and Scripting

How to find all files which has names in uppercase in a directory

i want to display all the files which has their names in the Uppercase in a particular directory...guide.. (6 Replies)
Discussion started by: sheelsadan
6 Replies

3. Shell Programming and Scripting

convert to uppercase in specific table

Hi All, I'm a newbie here, i'm just wondering is it possible to convert into uppercase the records in specific field? ex. table name = mytable field1 field2 field3 abd erfdF fdsfdsfsd how can i convert into uppercase the field2 using sybase? Please advise, ... (2 Replies)
Discussion started by: nikki1200
2 Replies

4. Shell Programming and Scripting

Trying to find number of uppercase and lowercase letters.

Hello Guys, I am writing a script which check each line for how many Uppercase and Lowercase letter of a given file. Please check my script as follow: l=0 while read line do echo Line `expr $l + 1` has ` tr -cd "" < $line | wc -c` uppercase letters and `tr -cd "" < $line | wc -c`... (3 Replies)
Discussion started by: kasparov
3 Replies

5. Shell Programming and Scripting

Convert lowercase to uppercase

listprocs.sh contains ps -ef | grep "swikar" 1) Write a shell script to convert an input file to all upper case. Name your shell script toupper.sh. Hint: tr ' ' ' ' will convert all lower case letters to upper case To use your script, try the following command: cat... (1 Reply)
Discussion started by: swikar
1 Replies

6. Shell Programming and Scripting

how to convert user input to uppercase

Hi, how to convert user input (lowercase) to uppercase in the dos batch file ? echo. SET /p user1=Enter username: SET user2=%user1%V echo. echo %user1% echo. echo %user2% echo. With Regards (7 Replies)
Discussion started by: milink
7 Replies

7. Shell Programming and Scripting

Convert the first letter of each line to uppercase

Hi, I have the following file: /* ----------------- ADP2DAILY_Box ----------------- */ insert_job: ADP2DAILY_Box job_type: b owner: mbprwork permission: gx,wx date_conditions: 1 days_of_week: mo,tu,we,th,fr exclude_calendar: mtg_holidays start_times: "1:00" description: "Process Daily... (4 Replies)
Discussion started by: ramky79
4 Replies

8. UNIX for Dummies Questions & Answers

Convert string to uppercase

i have this piece of small code that checks for *.CSV files. NUMFILES=`ls -1 *.CSV | wc -l` for filename in $(ls -1 *.CSV) do ... done it works only if the files has an uppercase of *.CSV extension. however, when there is a file of the same type but has lowercase *.csv... (1 Reply)
Discussion started by: wtolentino
1 Replies

9. Shell Programming and Scripting

sed help to convert from lowercase to uppercase and vice versa!

Hello, can sed be used to convert all letters of a file from uppercase to lowercase and vice versa?i know tr command can be used but with sed is it possible? i came up with this :- sed 'y///' file1 actually the above command is also not working! Please help me. Thanks in advance :) (6 Replies)
Discussion started by: salman4u
6 Replies

10. Shell Programming and Scripting

How convert lowercase or uppercase

It will only accept one argument where it should be upper or lowercase. if user choose to convert filnames to upper case than it should convert to upper or vice versa. if no action taken by the user then should not do anything any of the files in the current directory. (5 Replies)
Discussion started by: Alex20
5 Replies
Login or Register to Ask a Question