![]() |
|
|
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 |
| Escaping specific character in awk | brainyoung | Shell Programming and Scripting | 8 | 12-16-2008 11:14 PM |
| How to extract first column with a specific character | selamba_warrior | Shell Programming and Scripting | 3 | 05-22-2008 06:14 AM |
| count occurences of specific character in the file | superprogrammer | HP-UX | 9 | 04-09-2008 12:05 PM |
| replace character in a string pattern and save the change in same file | mihir0011 | Shell Programming and Scripting | 2 | 09-26-2007 06:31 PM |
| How to add character in specific position of a string? | victorlung | Shell Programming and Scripting | 5 | 09-01-2006 11:33 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
How to change a specific character in a file
Hi,
I have a data file with following structure: a|b|c|d|3|f1|f2|f3 a|b|c|d|5|f1|f2|f3|f4|f5 I want to change this data to: a|b|c|d|3|f1;f2;f3 a|b|c|d|5|f1;f2;f3;f4;f5 Data in column 5 tells the number of following fields. All fields delimiter after the 5th column needs to be changed to ";" Please help how can this be done in any scripting language sed, awk or perl? Regards Sandeep |
|
||||
|
Code:
awk -F'|' ' {OFS="|";
six="";
for(i=6;i<=NF;i++)
{ six=six $i ";" }
print $1,$2,$3,$4,$5,six
}' filename
input & output: Quote:
|
|
||||
|
Thanks Jim. It helped me in getting started. Just one followup: If the file is as:
a|b|c|d|3|f;;1;|f2;;0;|f3;;1; a|b|c|d|5|m;;1;|x;;1;|f3;;0;|f4;;1;|f5;;1; how can I change to a|b|c|d|3|f;f2;f3; a|b|c|d|5|m;x;f3;f4;f5; Basically I need to starting from 6th column to the end of line, delete ";1;|" or ";0;|" Thanks again for your help. Regards Sandeep |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|