![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| getopts alternative? | krishmaths | Shell Programming and Scripting | 3 | 04-06-2008 01:43 AM |
| Alternative to date +%s | Data469 | HP-UX | 6 | 03-31-2008 03:28 PM |
| .NET Alternative | goon12 | UNIX for Dummies Questions & Answers | 3 | 04-06-2005 12:07 PM |
| cut -f (or awk alternative) | gefa | Shell Programming and Scripting | 6 | 03-02-2005 01:26 PM |
| loop alternative? | apalex | Shell Programming and Scripting | 2 | 05-02-2002 12:47 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Using awk (or an alternative)
Hi,
I'm trying to echo a variable that has values separated by colons, putting each value on a new line. So as an example, a variable I might have would contain: My name is Earl:My name is Dorothy:My name is Bernard: And I want the output: My name is Earl My name is Dorothy My name is Bernard Also, I will be unaware of how many values the colon separated variable will contain (as it is generated by another function), so whatever is used will need to be flexible enough to accommodate any number of values. I'm not very competent in awk, so is there a way this can be done either with awk or with something else? Also, is it possible to specify a field separator (such as a colon or comma) to the for command? |
|
||||
|
Code:
echo "name is Earl:My name is Dorothy:My name is Bernard:" | tr ':' '\n' Code:
echo "name is Earl:My name is Dorothy:My name is Bernard:" | sed "s/:/\\ /g" Code:
echo "name is Earl:My name is Dorothy:My name is Bernard:" | awk ' gsub( ":" , "\n" ,$0 ) ' |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|