![]() |
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 |
| perl help for comma seperated output | namishtiwari | Shell Programming and Scripting | 3 | 06-15-2009 05:21 AM |
| Removing blank lines from comma seperated and space seperated file. | pinnacle | Shell Programming and Scripting | 11 | 05-08-2009 12:58 PM |
| change list to comma seperated items | insania | Shell Programming and Scripting | 2 | 10-03-2007 06:21 PM |
| Comma Seperated List of Values | brap45 | Shell Programming and Scripting | 9 | 02-23-2006 05:12 AM |
| Handling .CSV( Comma seperated value) in awk | Laud12345 | Shell Programming and Scripting | 1 | 05-09-2005 05:41 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Script to append a value seperated by comma
I have a file like below. How can I add a new value after moss separated by a comma. This adding script should work in such a way that each time i pass a value it should be added one after the other separated by commas.
Code:
hru:122: hello:123:john,philip,mary,kp,moss hi:124: bye:125: |
|
||||
|
thanks a lot for the reply!!
i want this to add only for "hello".. how to do that...? not generic..!! can anybody please help me to understand the above code too?? ---------- Post updated at 10:46 PM ---------- Previous update was at 06:47 AM ---------- myfile Code:
hru:122: hello:123:john,philip,mary,kp,moss hi:124: bye:125: hi:124: bye:125: hi:124: bye:125: tata:125:pipe,grep So if the new value i have is foo, the modified file should be like this.. Code:
hru:122: hello:123:john,philip,mary,kp,moss,foo hi:124: bye:125: hi:124: bye:125: hi:124: bye:125: tata:125:pipe,grep Code:
awk -v val='foo' '!/:$/ {$0=$0 "," val}1' myfile > myfilenew
cat myfilenew > myfile
rm -rf myfilenew
the new myfile Code:
hru:122: hello:123:john,philip,mary,kp,moss,foo hi:124: bye:125: hi:124: bye:125: hi:124: bye:125: tata:125:pipe,grep,foo Last edited by Tuxidow; 08-25-2009 at 03:46 AM.. |
|
|||||
|
so, take a quick look at this link: 10 Awk Tips, Tricks and Pitfalls - good coders code, great reuse
hope that helps! |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|