![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| getopts alternative? | krishmaths | Shell Programming and Scripting | 3 | 04-05-2008 10:43 PM |
| Alternative to date +%s | Data469 | HP-UX | 6 | 03-31-2008 12:28 PM |
| .NET Alternative | goon12 | UNIX for Dummies Questions & Answers | 3 | 04-06-2005 09:07 AM |
| cut -f (or awk alternative) | gefa | Shell Programming and Scripting | 6 | 03-02-2005 09:26 AM |
| loop alternative? | apalex | Shell Programming and Scripting | 2 | 05-02-2002 09:47 AM |
|
|
LinkBack | Thread Tools | 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? |
| Forum Sponsor | ||
|
|
|
|||
|
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 ) ' |