CamelCasify file names (sed?)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting CamelCasify file names (sed?)
# 1  
Old 12-03-2007
CamelCasify file names (sed?)

Dear forum,

I need to rename a bunch of files according to their first line, in CamelCase. I am having problems with the conversion from "normal string title" or "NST syndrome" to, respectively, "NormalString" or "NSTSyndrome".

First character of a word to uppercase and drop spaces.

I was struggling to do this with sed, using hold space and swaping... but had no results. It keeps grabbing the whole line.

Any ideas?

Grateful in advance.
# 2  
Old 12-03-2007
With ksh:
Code:
$ cat camel
#! /usr/bin/ksh
typeset -u first

( cat << END
camel case
NST Syndrome
The Living End
fix ME
fix me too
END
) | while IFS= read input ; do
        set -A words $input
        i=0
        output=""
        while ((i<${#words[*]})) ; do
                rest=${words[i]#?}
                first=${words[i]%$rest}
                output="${output}${first}${rest}"
                ((i=i+1))
        done
        echo input = $input
        echo output = $output
        echo
done
exit 0
$ ./camel
input = camel case
output = CamelCase

input = NST Syndrome
output = NSTSyndrome

input = The Living End
output = TheLivingEnd

input = fix ME
output = FixME

input = fix me too
output = FixMeToo

$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

sed awk: split a large file to unique file names

Dear Users, Appreciate your help if you could help me with splitting a large file > 1 million lines with sed or awk. below is the text in the file input file.txt scaffold1 928 929 C/T + scaffold1 942 943 G/C + scaffold1 959 960 C/T +... (6 Replies)
Discussion started by: kapr0001
6 Replies

2. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

3. Shell Programming and Scripting

Change the file name and copy old file content to new file names.

Hi, I have a files in a directory as below :- ls -1 mqdepth-S1STC02 proc-mq-S1STC01 proc-mq-S1STC02 proc-mq-S1STC03 Whereever i have S1STC i need to copy them into new file with file name S2STC. expected output :- ls -1 mqdepth-S2STC02 proc-mq-S2STC01 proc-mq-S2STC02... (3 Replies)
Discussion started by: satishmallidi
3 Replies

4. Shell Programming and Scripting

making find/sed to include directory names with spaces

how can i make find/sed to include directory names with spaces the command is like this for i in `find wp-content/themes -type f -print0 | xargs -0 grep -l -iE 'e'`;do sed -i -e 's/word1/word2/gI' "$i";done but it skips one directory names with spaces sed: can't read ./Nova: No such... (5 Replies)
Discussion started by: vanessafan99
5 Replies

5. Shell Programming and Scripting

Split File by Pattern with File Names in Source File... Awk?

Hi all, I'm pretty new to Shell scripting and I need some help to split a source text file into multiple files. The source has a row with pattern where the file needs to be split, and the pattern row also contains the file name of the destination for that specific piece. Here is an example: ... (2 Replies)
Discussion started by: cul8er
2 Replies

6. Shell Programming and Scripting

Searching for file names in a directory while ignoring certain file names

Sun Solaris Unix Question Haven't been able to find any solution for this situation. Let's just say the file names listed below exist in a directory. I want the find command to find all files in this directory but at the same time I want to eliminate certain file names or files with certain... (2 Replies)
Discussion started by: 2reperry
2 Replies

7. Linux

sed to fix view names

I have a ddl file which have lots of view in it. I want to replace all the existing views with VW_< view name> . I am prefixing VW to existing view name . For example, In old file grep on view is like this CREATE VIEW OPSDM001.PROVIDER_MBR_PRI ( MBR_PRI_PROV_SYS_ID,... (6 Replies)
Discussion started by: capri_drm
6 Replies

8. Shell Programming and Scripting

SED - editing file names (End of line problem?)

For lists in sed, to say what to replace, is this correct: I am hoping that this would recognise that either a "." is present, or that the substitution happens at the end of the line. For files with extensions , my script works perfectly. My problem is, files without extentions, i.e. . ... (1 Reply)
Discussion started by: busillis
1 Replies

9. OS X (Apple)

changing multiple directory names w/ sed

ive looked and couldnt find an answer... can someone tell me how i can replace spaces and characters with an "_" on multiple folders? thanx muchly. (1 Reply)
Discussion started by: RahJiggah
1 Replies

10. Shell Programming and Scripting

Reading file names from a file and executing the relative file from shell script

Hi How can i dynamically read files names from a list file and execute them from a single shell script. Please help its urgent Thanks in Advance (4 Replies)
Discussion started by: anushilrai
4 Replies
Login or Register to Ask a Question