![]() |
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 |
| oneliner:sing SED on a specific column | chaseeem | Shell Programming and Scripting | 8 | 07-15-2008 06:10 AM |
| How to extract first column with a specific character | selamba_warrior | Shell Programming and Scripting | 3 | 05-22-2008 05:14 AM |
| How to read a specific column into variable | victorcheung | Shell Programming and Scripting | 2 | 04-18-2008 01:49 AM |
| (cont) Retrieve line from a file based on a value in specific column | efernandes | UNIX for Dummies Questions & Answers | 0 | 01-27-2007 01:00 PM |
| Retrieve line from a file based on a value in specific column | efernandes | UNIX for Dummies Questions & Answers | 1 | 01-27-2007 11:04 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
subtitute specific column in line
Hi All,
I have problem to solve aaaa,aaaaa,aaa,aaaa,aaa,aa ,aa bbbb,bbbbbbbbb,bbbb,bbbbb ,bb to aaaa;aaaaa,aaa ;aaaa;aaa,aa ;aa bbbb;bbbbbbbbb;bbbb;bbbbb ;bb i try use sed to find and replace, but dont know how to replace specific column position. can u help me?? thx for the comment. |
|
||||
|
echo "aaaa;aaaaa;aaa ;aaaa;aaa;aa ;aa"|awk -F ";" '{$2="bbbbbbbb"; printf "%s;%s;%s;%s;%s\n", $1,$2,$3,$4,$5}'
awk -F sets the delimiter for columns and then each column is represented by $1 $2 $3 $4 $5. Change them as you see fit. |
|
||||
|
what i'm concern is, replace all commas delimiter to semicolon except several column
e.g i have a file contains two lines: aaaa,aaa,aa,aaaa,aaaa aa cccc,ccccc ,cccc,cccc,cc and i want change it into aaaa;aaa,aa;aaaa;aaaa aa cccc;ccccc ;cccc;cccc,cc *sorry my english not well enough Last edited by MomoChan; 08-25-2008 at 06:00 AM.. |
|
||||
|
echo "aaaa,aaa,aa,aaaa,aaaa aa"|sed -e 's/a/c/g' | awk -F "," '{printf "%s;%s%s;%s;%s,%s\n", $1,$2,$3,$4,substr($5,0,4),substr($5,6,2)}'
I hope you can understand the code. Like I said with the code I already had gave you it was possible to change any field with appropriate tweaking. |
|
||||
|
Quote:
and i modify to echo "aaaa,aaa,aa,aaaa,aaaa aa" | awk -F "," '{printf "%s;%s%s;%s;%s,%s\n", $1,$2,$3,$4,substr($5,0,4),substr($5,6,2)}' from ur code, it will change aaaa,aaa,aa,aaaa,aaaa aa into aaaa;aaaaa;aaaa;aaaa,aa the result line length reduced,... it should be aaaa;aaa,aa;aaaa;aaaa aa |
|
||||
|
in my input sample
aaaa,aaa,aa,aaaa,aaaa aa i just want to change commas in position 5,12,17 into semicolon.. no change in data i try to make an array and make a script, see below set -A dlm -- 5 12 17 echo ${#dlm[*]} inc=0 echo "cat FILENAME | sed \ " > ascript while [ $inc -lt ${#dlm[*]} ] ; do cmd=" -e '/^\(.\{${dlm[$inc]}\}\),\(.*\)/ s//\1\;\2/g' \ " echo $cmd >> ascript let inc=inc+1 done chmod 775 ascript ascript but still problem occurs, is there somtin wrong with my script ?? Last edited by MomoChan; 08-25-2008 at 08:56 AM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|