- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Shell script question using sed or awk
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2006 01:24 AM
тАО04-17-2006 01:24 AM
john.doe
How do i convert it to:
John Doe
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2006 01:35 AM
тАО04-17-2006 01:35 AM
Re: Shell script question using sed or awk
echo john.doe |tr [:lower:] [:upper:] |tr . " "
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2006 01:43 AM
тАО04-17-2006 01:43 AM
Re: Shell script question using sed or awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2006 01:59 AM
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2006 02:05 AM
тАО04-17-2006 02:05 AM
Re: Shell script question using sed or awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2006 02:11 AM
тАО04-17-2006 02:11 AM
Re: Shell script question using sed or awk
#!/usr/bin/awk -f
# convert upper case letters to lower case
BEGIN {
SEPARATOR_CHAR=".";
LC="abcdefghijklmnopqrstuvwxyz";
UC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
}
{
out="";
separator=0;
# look at each character
for(i=1;i<=length($0);i++) {
# get the character to be checked
char=substr($0,i,1);
j=index(LC,char);
# is it the first letter?
if (( i == 1 ) || ( separator == 1 )) {
# print (char);
out = out substr(UC,j,1);
separator = 0;
}
else if (char == SEPARATOR_CHAR ) {
char=" ";
out = out char
separator=1
} else {
out = out char;
}
}
printf("%s\n", out);
}
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2006 02:16 AM
тАО04-17-2006 02:16 AM
Re: Shell script question using sed or awk
With 'awk' the problem becomes more tedious since you would have to isolate the first character of each "word" (say with 'substr'); convert it to uppercase with 'toupper'; and then convert the remaining characters of that word to lowercase with 'tolower'. Perl offers far, far many more features than does 'awk'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2006 02:22 AM
тАО04-17-2006 02:22 AM
Re: Shell script question using sed or awk
echo "john doe"|perl -ne '@a=split;foreach (@a) {push @b,ucfirst};print "@b\n"'
Could you give an explanation of the statement.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2006 02:42 AM
тАО04-17-2006 02:42 AM
Re: Shell script question using sed or awk
# echo "john doe"|perl -ne '@a=split;foreach (@a) {push @b,ucfirst};print "@b\n"'
The perl switch '-n' says create a read loop. For every line read, split on whitespace (blanks, or tabs) the line's elements into a list called "a". Now, walk each element of list "a", and uppercase the first character of each element. As you do this, "push" (store) the result into a new list called "b". When every element in a line has been handled, print the modified line.
You could use this with a file, like:
# perl -ne '@a=split;foreach (@a) {push @b,ucfirst};print "@b\n"' yourfile
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-17-2006 02:56 AM
тАО04-17-2006 02:56 AM
Re: Shell script question using sed or awk
> testFile
printf "\n" >> testFile
echo "john.doe"|perl -ne '@a=split;foreach (@a) {push @b,ucfirst};print "@b\n\n"' >> testFile
ps -U john.doe >> testFile
Its only the echo line that is not appending to testFile. Any ideas why?