08-31-2007
awk: find and replace in certain field only, help needed
I got a sample file like this.
$ cat test
12|13|100|s
12|13|100|s
100|13|100|s
12|13|100|s
I want to replace all 100 by 2000 only in 3rd field using "awk"
This is replacing all 100's :-(
$ awk -F "|" '{gsub( /100/,"2000");print}' test
12|13|2000|s
12|13|2000|s
2000|13|2000|s
12|13|2000|s
I tried using something like this also - '$3 ~ /100/
but no luck :-(
Please help.
HTH,
jkl_jkl
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
I have a file "dbshot.xml" that contains lines that need replacing in a batch format but the parameters are based on two lines.
Ex.
<role roletype="01">
<status>1
needs to be changed to
<role roletype="01">
<status>0
I can't use simply "<status>1" replace since the... (2 Replies)
Discussion started by: E Orgill
2 Replies
2. Shell Programming and Scripting
HI all
I have a problem, I need to replace a field in a file, but only in the lines that have some pattern, example:
100099C01101C00000000059394200701CREoperadora_TX
100099C01201C00000000000099786137OPERADORA_TX2
in the example above I need to change the first field from 1 to 2 only if... (3 Replies)
Discussion started by: sergiioo
3 Replies
3. UNIX for Dummies Questions & Answers
I have a file 'test.out' with contents:
1|1|10|10|I|asdf|
2|1|10|10|I|sdfg|
4|1|10|10|I|hgfj|
34|0|10|10|I|sdg|
I want to modify the fifth column with value 'I' to 'A' for only the last line. Below is what I expect to see:
1|1|10|10|I|asdf|
2|1|10|10|I|sdfg|
... (3 Replies)
Discussion started by: ChicagoBlues
3 Replies
4. UNIX for Dummies Questions & Answers
Hi,
I have a requirement for taking an particular number in a log file. if i grep for the particular string it will retrieve the entire line for the particular string. but i want to display only the string from each line which i am searching for,
Note: The searching field varies its position... (3 Replies)
Discussion started by: senthilkumar_ak
3 Replies
5. UNIX for Advanced & Expert Users
Hello All
I have always had a question about find and replace in Vi. As this uses Vi, sed, and RegEx I never knew how or where to post the question but I thought I would give it a shot here. Say I have a text file filled with the following:
Sue, your IP address is 192.168.1.10 which is... (4 Replies)
Discussion started by: NoSalt
4 Replies
6. Shell Programming and Scripting
Hi all,
I have a huge file and I need to get ride of the fields 6-11 and replace the blanks in field 5 with a missing value(99999).
159,93848,5354,343,67898,45,677,5443,434,5545,45
677,45545,3522,244,
554,54344,3342,456,
344,43443,2344,444,23477... (12 Replies)
Discussion started by: GoldenFire
12 Replies
7. Shell Programming and Scripting
Hello All,
I have a file with contents like
apple|ball|charlie|David|
England|France|Germany|
Ireland|Japan|King|London|
Man|Nancy|Orange|
here the column delimiter is |
so if any of the lines/rows in the file has 3 only records (last field is empty), i want to place a | at the end of... (4 Replies)
Discussion started by: vinredmac
4 Replies
8. Shell Programming and Scripting
hi,
i having a file with | seperated in which i need to search char in 3rd column and replace with null. i need to replace only the coulmn where character occurs in 3rd field
for eg:
file1.txt
xx|yy|xx|12
output file:
xx|yy||12 (5 Replies)
Discussion started by: rohit_shinez
5 Replies
9. Shell Programming and Scripting
Hi All,
i have a file like
col1 col2 col3
13 24 NA
12 13 14
11 12 13
14 22 NA
18 26 NA
in this file if i found "NA" other values in the line are also replace by NA
Could you help me! (7 Replies)
Discussion started by: Shenbaga.d
7 Replies
10. Shell Programming and Scripting
hai guys,
pick the 1st field and calculate max length.
if suppose max length is 2,
then compare the all records if <2 then add zero's prefix of the record.
for ex:
s.no,sname
1,djud
37,jtuhe
in this max length of the 1st field is 2 right
the output wil be
s.no,sname
01,djud... (6 Replies)
Discussion started by: Suneelbabu.etl
6 Replies
LEARN ABOUT DEBIAN
xpacode
xpacode(7) SAORD Documentation xpacode(7)
NAME
XPACode - Where to Find Example/Test Code
SYNOPSIS
The XPA source code directory contains two test programs, stest.c, and ctest.c that can serve as examples for writing XPA servers and
clients, respectively. They also can be used to test various features of XPA.
DESCRIPTION
To build the XPA test programs, execute:
make All
in the XPA source directory to generate the stest and ctest programs. (NB: this should work on all platforms, although we have had prob-
lems with unresolved externals on one Sun/Solaris machine, for reasons still unknown.)
The stest program can be executed with no arguments to start an XPA server that contains the access points: xpa, xpa1, c_xpa (containing
sub-commands cmd1 and cmd2), and i_xpa. You then can use xpaset and xpaget to interact with these access points:
cat xpa.c | xpaset xpa # send to xpa
cat xpa.c | xpaset "xpa*" # send to xpa and xpa1
xpaget xpa # receive from xpa
xpaget xpa* # receive from xpa and xpa1
etc. You also can use ctest to do the same thing, or to iterate:
ctest -s -l 100 xpa # send to xpa 100 times
ctest -s -l 100 "xpa*" # send to xpa and xpa1 100 times
ctest -g -l 100 xpa # receive from xpa 100 times
ctest -g -l 100 "xpa*" # receive from xpa and xpa1 100 times
More options are available: see the stest.c and ctest.c code itself, which were used extensively to debug XPA.
The file test.tcl in the XPA source directory gives examples for using the XPATclInterface.
SEE ALSO
See xpa(7) for a list of XPA help pages
version 2.1.14 June 7, 2012 xpacode(7)