Hi all,
I am having the file below
I need that as below
Thanks,
Arun
Hi all,
I am having the file below
I need that as below
Thanks,
Arun
what have you tried so far and where exactly are you stuck?
I am able to get the position value by below command and not able to transform that to 1 and replace in file
cut -d, -f3 S2007080A.011317.0000043042.SUPP.CSVX
I've noticed there're a number of awk-based proposed solutions posted for your 336 posts.
Could you try something with awk and see how far you get, please!
Able to extract the value using AWK but not able to replace that in the file
awk -F, '{print $3=1}' FSDS.CSVX
Below also not working
awk 'BEGIN{OFS=FS=","}$3=="NOT APPLICABLE"{$3=1}{print}' file
awk -F "|" '{ if ( $3 =="NOT APPLICABLE" ) print $1"|"$2"|"1"|$4' file
Files do not work that way. You can't write to the same file you're reading from. A few commands can pretend, but they're really using temp or whole-memory buffers files like everything else does:
awk ... filename > /tmp/$$
# BACK UP YOUR DATA before doing this! One mistake and filename's contents are blown away
cat /tmp/$$ > filename
rm -f /tmp/$$
awk doesn't provide the facility to edit "in-place". redirect to a temp file and then mv
.
Make sure you provide a correct field separator.
Thanks all.
Not sure what I am doing wrong . Nothing is happening no result
awk -F"," '{if ($3 =="NOT APPLICABLE") {print $1}}' file
I am planning to make this as
awk -F"," '{if ($3 =="NOT APPLICABLE") {print $1|$2|"1"|$4}}' file
you cannot print like that. Try assigning the third field a new value and then print the whole record.
The text you are looking for is not NOT APPLICABLE
, it is "NOT APPLICABLE"
May be easier as awk -F, -v OFS="," '/NOT APPLICABLE/ { print $1,$2,"1",$4 }' input
// is a regex search, which will find it within the quotes.
exactly. Just figured that out and below is working . Escaped the quotes
awk 'BEGIN {FS=","} {if($3=="\"NOT APPLICABLE\""){print $1","$2","1","$4}}' AK >> tmp && mv tmp AK
I really hope that worked first try as if it didn't you just trashed your input data.
Coronna688, this will drop the quotes from the third field.
awk -F, '$3~/"NOT APPLICABLE"/{$3=qq 1 qq}1' qq='"' OFS=, myFile