Other *NIXThis forum is for the discussion of any UNIX platform that does not have its own forum. Examples would include HP-UX, IRIX, Darwin, Tru64 and OS X.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
If I assume your example is relevant (there's not much info in your post) then this works:
Code:
sed -r '/\<[A-Z]+\>/{s/./& /g;s/\.//}' infile
The green part looks for capitalized words. The \< and \> make sure that individual words are matched.
The brown part changes individual characters to individual characters followed by a space.
The blue part removes the trailing dot.
Here's an example run:
Code:
$ cat infile
USA
USA.
XXXIIV
Word
$ sed -r '/\<[A-Z]+\>/{s/./& /g;s/\.//}' infile
U S A
U S A
X X X I I V
Word
BTW: The above will not work when there are multiple words on one line......
{
for (i = 1; i <= NF; i++)
if ( $i == toupper($i)) {
gsub(/[[:punct:]]/,"",$i)
gsub(/./,"& ",$i)
gsub(/ +$/,"",$i)
}
}
1
The first gsub removes punctuation, the second one adds a space after each character, the third one removes the extra blank space at the end of the word. Anyway, since you've posted in other *nix forum, it might not work for you. Which system are you running on? And which version of sed or awk/nawk/gawk do you have?
{
for (i = 1; i <= NF; i++)
if ( $i == toupper($i)) {
gsub(/[[:punct:]]/,"",$i)
gsub(/./,"& ",$i)
gsub(/ +$/,"",$i)
}
}
1
The first gsub removes punctuation, the second one adds a space after each character, the third one removes the extra blank space at the end of the word. Anyway, since you've posted in other *nix forum, it might not work for you. Which system are you running on? And which version of sed or awk/nawk/gawk do you have?
Might work but I don't know how is it written into single line.
I am using Ubuntu 11.04 and
sed --version
GNU sed versio 4.2.1
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.