[R] Help with R script
Vijayan Padmanabhan
V.Padmanabhan at itc.in
Thu Jul 13 13:12:45 CEST 2017
Dear R-help Group
Scenario 1:
I have a text file running to 1000 of lines...that
is like as follows:
[922] "FieldName: Wk3PackSubMonth"
[923] "FieldValue: Apr"
[924] "FieldName: Wk3PackSubYear"
[925] "FieldValue: 2017"
[926] "FieldName: Wk3Code1"
[927] "FieldValue: "
[928] "FieldValue: K4"
[929] "FieldName: Wk3Code2"
[930] "FieldValue: "
[931] "FieldValue: Q49"
I want this to be programmatically corrected to
read as follows: (All consecutive lines starting
with FieldValue is cleaned to retain only one
line)
[922] "FieldName: Wk3PackSubMonth"
[923] "FieldValue: Apr"
[924] "FieldName: Wk3PackSubYear"
[925] "FieldValue: 2017"
[926] "FieldName: Wk3Code1"
[927] "FieldValue: K4"
[928] "FieldName: Wk3Code2"
[929] "FieldValue: Q49"
Scenario 2:
In the same file, in some instances, the lines
could be as follows: in this case, wherever a line
is beginning with FieldName and the subsequent
line is not displaying a FieldValue, I would want
to programmatically identify such lines and insert
FieldValue (as blank).
[941] "FieldName: Wk3Code6"
[942] "FieldValue: "
[943] "FieldName: Wk3Code7"
[944] "FieldValue: "
[945] "FieldName: Wk3PackWSColorStiffRemarkCode1"
[946] "FieldName: Wk3PackWSColorWrappRemarkCode1"
[947] "FieldName:
Wk3PackWSDelamiStiffRemarkCode1"
ie in the above, it should be replaced as
[941] "FieldName: Wk3Code6"
[942] "FieldValue: "
[943] "FieldName: Wk3Code7"
[944] "FieldValue: "
[945] "FieldName: Wk3PackWSColorStiffRemarkCode1"
[946] "FieldValue: "
[947] "FieldName: Wk3PackWSColorWrappRemarkCode1"
[948] "FieldValue: "
[949] "FieldName:
Wk3PackWSDelamiStiffRemarkCode1"
[950] "FieldValue: "
Can anybod suggest how to acheive this in R?
Thanks for your time.
Regards
VP
Disclaimer:\ This Communication is for the exclusive use...{{dropped:8}}
More information about the R-help
mailing list