Find Word in Column with replace


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find Word in Column with replace
# 1  
Old 05-02-2017
Find Word in Column with replace

Hi ALL

i have file.txt with text :

Code:
4c:66:41:6b:b5:5f, 00:00,00:00, -22:-25, users1, 10.101.3.119, host1
4c:66:41:2c:c1:5a, 00:00,00:00, -21:-25, 10.101.3.112, host1
4c:66:41:6b:b1:5e, 00:00,00:00, -21:-25, users1, 10.101.3.113, host1
4c:66:41:2c:c1:5b, 00:00,00:00, -21:-25, 10.101.3.115, host1

The result should be:

Code:
4c:66:41:6b:b5:5f, 00:00,00:00, -22:-25, users1, 10.101.3.119, host1
4c:66:41:2c:c1:5a, 00:00,00:00, -21:-25, anony, 10.101.3.112, host1
4c:66:41:6b:b1:5a, 00:00,00:00, -21:-25, users1, 10.101.3.113, host1
4c:66:41:2c:c1:5b, 00:00,00:00, -21:-25, anony, 10.101.3.115, host1

Can't anybody help me?

Thanks,
DChristian

Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 05-02-2017 at 05:15 AM.. Reason: Added CODE tags.
# 2  
Old 05-02-2017
Try
Code:
awk -F, 'NF == 6 {$5 = " anony" OFS $5} 1' OFS="," file
4c:66:41:6b:b5:5f, 00:00,00:00, -22:-25, users1, 10.101.3.119, host1
4c:66:41:2c:c1:5a, 00:00,00:00, -21:-25, anony, 10.101.3.112, host1
4c:66:41:6b:b1:5e, 00:00,00:00, -21:-25, users1, 10.101.3.113, host1
4c:66:41:2c:c1:5b, 00:00,00:00, -21:-25, anony, 10.101.3.115, host1

If that doesn't satisfy your needs, please be way more specific when phrasing your requirement.
# 3  
Old 05-02-2017
Thanks For Rudy..

for specific file :

Code:
4c:66:41:6b:b5:5f, 00:00,00:00, -22:-25, robert, 10.101.3.119, host1
4c:66:41:2c:c1:5a, 00:00,00:00, -21:-25, 10.101.3.112, host1
4c:66:41:6b:b1:5a, 00:00,00:00, -21:-25, Julia, 10.101.3.113, host1
4c:66:41:2c:c1:5b, 00:00,00:00, -21:-25, 10.101.3.115, host1
4c:66:41:6b:b1:5f, 00:00,00:00, -21:-25, Justin, 10.101.3.116, host1
4c:66:41:6b:b1:5c, 00:00,00:00, -21:-25, Fredy, 10.101.3.110, host1
4c:66:41:6b:b1:7a, 00:00,00:00, -21:-25, Josh, 10.101.3.123, host1

OUTPUT
Code:
4c:66:41:6b:b5:5f, 00:00,00:00, -22:-25, robert, 10.101.3.119, host1
4c:66:41:2c:c1:5a, 00:00,00:00, -21:-25, anony, 10.101.3.112, host1
4c:66:41:6b:b1:5a, 00:00,00:00, -21:-25, Julia, 10.101.3.113, host1
4c:66:41:2c:c1:5b, 00:00,00:00, -21:-25, anony, 10.101.3.115, host1
4c:66:41:6b:b1:5f, 00:00,00:00, -21:-25, Justin, 10.101.3.116, host1
4c:66:41:6b:b1:5c, 00:00,00:00, -21:-25, Fredy, 10.101.3.110, host1
4c:66:41:6b:b1:7a, 00:00,00:00, -21:-25, Josh, 10.101.3.123, host1

Help me please..

Thanks


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 05-02-2017 at 06:28 AM.. Reason: Added CODE tags.
# 4  
Old 05-02-2017
Help you with what??? In what way did the code RudiC provided fail to produce the output you wanted?

What operating system are you using?

What shell are you using?

What command did you use (based on what RudiC suggested in post #2 in this thread)? (PLEASE show us the exact command you used in CODE tags!)

What output did that command produce? (Please show us the exact output that command produced in CODE tags!)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find Word in Column with replace (2)

Dear ALL, I have sample file : 4c:66:41:6b:b5:5f, 00:00,00:00, -22:-25, robert, 10.101.3.119, host1 4c:66:41:2c:c1:5a, 00:00,00:00, -21:-25, 10.101.3.112, host1 4c:66:41:6b:b1:5a, 00:00,00:00, -21:-25, Julia, 10.101.3.113, host1 4c:66:41:2c:c1:5b, 00:00,00:00, -21:-25, 10.101.3.115, host1... (2 Replies)
Discussion started by: gnulyn
2 Replies

2. Shell Programming and Scripting

Shell Script @ Find a key word and If the key word matches then replace next 7 lines only

Hi All, I have a XML file which is looks like as below. <<please see the attachment >> <?xml version="1.0" encoding="UTF-8"?> <esites> <esite> <name>XXX.com</name> <storeId>10001</storeId> <module> ... (4 Replies)
Discussion started by: Rajeev_hbk
4 Replies

3. Shell Programming and Scripting

Find number of characters in a column and replace

Hi all, I want to count total no. of characters in a column. and if no. of charaters are more than 3 then it must replace it by splitted string. ie, it must place a space after 3 characters. Ex: 21 435g asd3dd jklfjwe wer column number 3 has 4 alphanumeric character, so it must be splitted... (3 Replies)
Discussion started by: CAch
3 Replies

4. Shell Programming and Scripting

Help with replace column data with specific word

Input file: Populus_trichocarpa 30 0 50 0 0 US Vitis_vinifera 1 18 2 8 6 US Populus_trichocarpa 1 5 100 0 0 US Arabidopsis_lyrata_subsp._lyrata 0 90 0 0 0 US Glycine_max 0 2 3 0 70 UK Desired output file: Populus_trichocarpa YES NO YES NO NO US Vitis_vinifera YES YES YES YES YES US... (4 Replies)
Discussion started by: perl_beginner
4 Replies

5. Shell Programming and Scripting

Find and replace a word in all the files (that contain the word) under a directory

Hi Everyone, I am looking for a simple way for replacing all the files under a directory that use the server "xsgd1234dap" with "xsdr3423pap". For Example: In the Directory, $pwd /home/nick $ grep -l "xsgd1234dap" *.sh | wc -l 119 I have "119" files that are still using... (5 Replies)
Discussion started by: filter
5 Replies

6. Shell Programming and Scripting

simple Word Capitalization (Title) find/replace

Hi! I'm looking for a simple script, especially a one liner script in tcsh or bash that will emulate the find/replace in all text apps. I want to change all uppercase caracters to Title word (in wich only the first caracter is UpperCase and the rest is lowercase) I can use sed command, but... (2 Replies)
Discussion started by: sstpierre68
2 Replies

7. Shell Programming and Scripting

find replace a pattern and following characters in a word

Suppose that I have a string "one:#red two:#yellow three:#gr'een four:#blu^e" and I want to replace the pattern :# and the following characters in the word with nothing. The output string should look "one two three four" How can I do this with sed. Some points to consider (a) the last word in... (1 Reply)
Discussion started by: superuser84
1 Replies

8. Shell Programming and Scripting

find and replace in first column

Dear All I need help with find and replacing a string:.. In the following example of a file named say <filename.gff> with 9 columns 1 ensembl chromosome 1 300239041 . . . ID=1;Name=chromosome:AGPv1:1:1:300239041:1 1 ensembl exon 3 104 ... (3 Replies)
Discussion started by: cs_novice
3 Replies

9. Shell Programming and Scripting

Find and replace duplicate column values in a row

I have file which as 12 columns and values like this 1,2,3,4,5 a,b,c,d,e b,c,a,e,f a,b,e,a,h if you see the first column has duplicate values, I need to identify (print it to console) the duplicate value (which is 'a') and also remove duplicate values like below. I could be in two... (5 Replies)
Discussion started by: nuthalapati
5 Replies

10. Shell Programming and Scripting

Find and replace a part of the word in Shell

I have a csv file in which there are numbers like 078976/9XXX 098754/8XXX I want to replace the XXX with null. I want to know the command/code to do this. I know how to replace the whole word/number. But don't know how to replace a part of it. Thanks in advance, Mihir (3 Replies)
Discussion started by: mihirk
3 Replies
Login or Register to Ask a Question