Masking a column using awk command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Masking a column using awk command
# 1  
Old 03-02-2009
Change A Column

Thanks...It was a spoiler for my Team...

Last edited by Diggi; 03-03-2009 at 09:19 AM..
# 2  
Old 03-02-2009
Code:
awk -F'|' '{print $1 "|" $2 "| 9999 |" $4 "|" $5 }'

# 3  
Old 03-02-2009
Code:
awk -F'|' -v OFS='|' '{$3="9999"}1' myFile

# 4  
Old 03-02-2009
@majormark....

your code is working...

@vgersh

your code is giving syntax error..


but i dont want a generic replacement...for example 9999 can be replaced by any variable...say abcd or 678890
# 5  
Old 03-02-2009
Quote:
Originally Posted by majormark
Code:
awk -F'|' '{print $1 "|" $2 "| 9999 |" $4 "|" $5 }'

You can explicitly specify the output field seperator...

awk -F '|' 'OFS="|" {print $1,$2,$3="9999",$4,$5}' myfile
# 6  
Old 03-02-2009
Quote:
Originally Posted by Diggi
@majormark....

your code is working...

@vgersh

your code is giving syntax error..
Care to share the specifics?
As always, if under Solaris, use nawk or /usr/xpg4/bin/awk
Quote:
Originally Posted by Diggi

but i dont want a generic replacement...for example 9999 can be replaced by any variable...say abcd or 678890
Code:
nawk -F'|' -v OFS='|' -v myVal='abcd' '{$3=myVal}1' myFile

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Masking with gsub command

My file "test.dat" data as below Requirement is to mask(replace) all english characters with "X" EXCEPT first 7 characters of every line. my command awk '{gsub("]","X")}1' test.dat looks not working properly, Appreciate any suggestion... (6 Replies)
Discussion started by: JSKOBS
6 Replies

2. UNIX for Dummies Questions & Answers

awk command to compare files by column

So I have this issue. I have 4 files. the first one is the master file who has all possible combinations: file 1 - a - b - c - d - e the other three have some of the letters and a number instead of - for example file 2 34 a 5 c file 3 10 b 12 ... (3 Replies)
Discussion started by: Quijotes
3 Replies

3. Shell Programming and Scripting

Print column details from fixed width file using awk command

hi, i have a fixed width file with multiple columns and need to print data using awk command. i use: awk -F "|" '($5 == BH) {print $1,$2,$3}' <non_AIM target>.txt for a delimiter file. but now i have a fixed width file like below: 7518 8269511BH 20141224951050N8262 11148 8269511BH... (5 Replies)
Discussion started by: kcdg859
5 Replies

4. Shell Programming and Scripting

How to Replace the value of a column using awk command?

Hi cat test.txt H|123|341|567|asfg D|dfg|trtyy|errt D|ert|frty|wer Here I need to replace the third column value with 100 of the first record only and while printing I need to print the full file content also..I am expecting a result like this H|123|100|567|asfg D|dfg|trtyy|errt... (3 Replies)
Discussion started by: saj
3 Replies

5. Shell Programming and Scripting

awk command to print only selected rows in a particular column specified by column name

Dear All, I have a data file input.csv like below. (Only five column shown here for example.) Data1,StepNo,Data2,Data3,Data4 2,1,3,4,5 3,1,5,6,7 3,2,4,5,6 5,3,5,5,6 From this I want the below output Data1,StepNo,Data2,Data3,Data4 2,1,3,4,5 3,1,5,6,7 where the second column... (4 Replies)
Discussion started by: ks_reddy
4 Replies

6. Shell Programming and Scripting

awk command - column merging

I have two files having 3 coulms and 1 column respectively file1.txt 0 22.89 35.60 10 22.80 35.61 20 22.70 35.63 30 22.32 35.68 50 19.23 35.79 75 16.10 35.59 100 15.00 35.52 125 14.45 35.46 150 13.91 35.41 200 12.94 35.28 ... (7 Replies)
Discussion started by: shashi792
7 Replies

7. Shell Programming and Scripting

awk command: column operations

I have a txt file with two columns Freq Loss 10 30 20 40 30 10 40 50 50 60i have used the below code to get the minimum value out of this array in second cloumn. awk 'NR==N{min=$N;max=$N}NR>N{if ($N>max){max=$N};if ($N<min){min=$N}}END {print... (3 Replies)
Discussion started by: shashi792
3 Replies

8. UNIX for Dummies Questions & Answers

AWK Command to find text in specific column

I'm new to scripting and would appreciate any help. I have a list of over 20 words in File1 that I need to find in columns 10-15 of File2. I need the entire row of File2 that the File1 list matches. I originally used a grep command which works, but provides File1 results that can be found... (3 Replies)
Discussion started by: Chillin
3 Replies

9. Shell Programming and Scripting

reg Mailx command or masking of mailid

I am using the mailx command of Unix through which I am able send mails but the problem is the from mail ID is automatically buit by unix as the (UNIX Box Name:---------------------------------) to mask the from id the option used by mailx is -r but for some security reasons this is blocked by the... (1 Reply)
Discussion started by: naren_chella
1 Replies
Login or Register to Ask a Question