![]() |
|
|
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. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hi
Can some tell to use AWK or SED in the following situtation file A has 10 columns, whenever column 10 has valuues AorBorCorDorE replace the column value with X else if it has GorH replace the column value with Y. I'm not too user which one to use, whether mix of both of anone wil do ? Thanks in advance BrainDrain |
|
||||
|
Hi,
I was just trying the following, however the value i'm trying to replace($7) with 'Z' for the occurences of 'A' retains it's orginal value. Am I doing something stupid ? awk -F"~" '{if ($7=='A') $7='Z' ; print $1"~"$7; }' cif_in.tsv |
|
||||
|
Hi,
Thanks for the reply, Well i'm able to evaluvate if ($7=='A') in AWK, however assignment was not happening. May be i should try printing directly the value as you mentioned, instead of assignment. I thought there must be much neat way of doing this in awk. |
|
|||||
|
A slight refinement to Perderabo's solution. This is a bit more awk-like. Code:
awk '$10 == "uu" { $10 = "@@" } { print }' adata
This can be generalized across multiple lines like this (in a bourne-like shell): Code:
awk '$10 == "uu" || $10 == "99" || $10 == "**" { $10 = "zz" }
$10 == "aa" || $10 == "bb" { $10 = "yy" }
{ print }' adata
This checks field 10 for the strings ("||" means logical OR) and replaces it via the assignment in braces. The final line prints all lines after replacement has been done (if it was needed). If you're using a C-shell-like shell, I'm told (but cannot confirm) that a backslash at the ends of the first two lines in apostrophes is needed. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|