arkhei
September 17, 2008, 4:35pm
1
I have this file:
NPANXX|BILLDATE|DIVCODE|COMID|RAO|LIKECODE|BOSS|SORD|STATECODE|
087001|BP01|H|SWBT| |041|IMR6|IMSR6|AR|
087002|BP03|H|SWBT| |042|IMR6|IMSR6|AR|
087003|BP05|H|SWBT| |043|IMR6|IMSR6|AR|
....
these are the things that i HAve to do:
Insert a new column named �TEST�
All lines starting with 090 should have a value under the 10th column �TEST� set to �CF5857�
LIKECODE (4th column) of all lines starting with 087 should be changes to �PHI�
Ikon
September 17, 2008, 4:37pm
2
This looks like homework... You cant have the perople here do your home work.
What you can do, I beleive, is post what you have done and where you are having issues and maybe someone will help you with a portion of the problem.
arkhei
September 17, 2008, 4:49pm
4
this is what i've done to insert new column but it does not work.
cat hl.dsldryloop | awk -F\|'{print $1"|"$2"|"$3"|"$4"|"$5"|"$6"|"$7"|"$8"|"$9"|TEST|" } ' >file.txt
Ikon
September 17, 2008, 4:55pm
5
This worked for me
awk -F \| '{print $1"|"$2"|"$3"|"$4"|"$5"|"$6"|"$7"|"$8"|"$9"|TEST|" } ' hl.dsldryloop
was missing space. "..awk -F \|'{print.." vs "..awk -F \| '{print.."
sed -e '1s/\|$/\|TEST\|/g' filename this will add the header TEST for first column..
hey guys please don't use cat command when you are going to use commands like grep,awk and sed....
arkhei
September 17, 2008, 5:04pm
8
it still doesn't work ..why is tha?
Ikon
September 17, 2008, 5:07pm
9
# cat test.txt
NPANXX|BILLDATE|DIVCODE|COMID|RAO|LIKECODE|BOSS|SORD|STATECODE|
087001|BP01|H|SWBT| |041|IMR6|IMSR6|AR|
087002|BP03|H|SWBT| |042|IMR6|IMSR6|AR|
087003|BP05|H|SWBT| |043|IMR6|IMSR6|AR|
# awk -F \| '{print $1"|"$2"|"$3"|"$4"|"$5"|"$6"|"$7"|"$8"|"$9"|TEST|" } ' test.txt
NPANXX|BILLDATE|DIVCODE|COMID|RAO|LIKECODE|BOSS|SORD|STATECODE|TEST|
087001|BP01|H|SWBT| |041|IMR6|IMSR6|AR|TEST|
087002|BP03|H|SWBT| |042|IMR6|IMSR6|AR|TEST|
087003|BP05|H|SWBT| |043|IMR6|IMSR6|AR|TEST|
#
arkhei
September 17, 2008, 5:11pm
10
what if i want to save it in a new file?
Ikon
September 17, 2008, 5:13pm
11
sed -e '1s/\|$/\|TEST\|/g' infilename > outfilename
arkhei
September 17, 2008, 5:13pm
12
Thanks. but TEST column should only be added at the first line
sed -e ''1s/\|$/\|TEST\|/g' -e 's/^090.*$/&CF5857\|/g' filename > outfile
this will solve your first and second question
arkhei
September 17, 2008, 5:56pm
15
thanks vidyarhar85 it works great. Thanks alot.
can you please explain your im quite confuse
thanks alot