Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
prog-1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pedro Folloni Pesserl
prog-1
Commits
2223a855
Commit
2223a855
authored
2 years ago
by
Pedro Folloni Pesserl
Browse files
Options
Downloads
Patches
Plain Diff
tshell:p3:sed one liner
parent
95d1be3d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tshell/tshell_p3.sh
+52
-18
52 additions, 18 deletions
tshell/tshell_p3.sh
with
52 additions
and
18 deletions
tshell/tshell_p3.sh
+
52
−
18
View file @
2223a855
...
...
@@ -24,9 +24,7 @@ confere_arq_saida() {
exit
2
fi
if
[
!
-f
$1
]
;
then
touch
$1
fi
echo
"version+pmid<title<abstract<keywords"
>
$1
}
XML
=
$1
...
...
@@ -37,32 +35,68 @@ CSV=$2
confere_arq_saida
$CSV
CSV
=
$(
realpath
$CSV
)
#
separar os campos úteis do arquivo xml.gz
#
converter o arquivo xml.gz para o formato csv
zcat
$XML
|
\
xgrep
-tx
"//PMID|//ArticleTitle|//Abstract|//MeshHeadingList"
|
\
# o sed acha um campo PMID, seguido de um campo ArticleTitle, seguido
# de um campo Abstract, e imprime. Se houver um campo MeshHeadingList
# após o Abstract, imprime também; se não, insere um vazio.
# o sed acha os campos úteis -- PMID seguido de ArticleTitle seguido
# de Abstract, seguido ou não de MeshHeadingList -- e converte no
# formato csv. No caso de não haver MeshHeadingList para um dado artigo,
# cria um campo vazio (<).
sed
-En
'
/<PMID/{
/PMID/{
s/<PMID Version="//;
s/">//;
s/<\/PMID>//;
N;
/<ArticleTitle>/{
/ArticleTitle/{
s/<ArticleTitle>/</;
s/<\/ArticleTitle>//;
N;
/<Abstract>/{
/Abstract/{
s/<Abstract> *<AbstractText>/</;
s/<\/AbstractText> *<\/Abstract>//;
p;
n;
/<MeshHeadingList>/{
/MeshHeadingList/{
s/ *<MeshHeading> *<Descriptor[^>]*>//g;
s/(<\/DescriptorName>|<\/QualifierName>) *(<Qualifier[^>]*>|<\/MeshHeading>)/, /g;
s/<MeshHeadingList>/</;
s/(, *|)<\/MeshHeadingList>//;
p;
};
/<PMID/{
i <MeshHeadingList></MeshHeadingList>
/PMID/{
i <
}
}
}
}'
>
$CSV
}'
>>
$CSV
# converter para o formato csv
# sed -i '
# /PMID/{
# s/<PMID Version="//;
# s/">//;
# s/<\/PMID>//;
# }
# /ArticleTitle/{
# s/<ArticleTitle>/</;
# s/<\/ArticleTitle>//;
# }
# /<[^>]*>/
# /Abstract/{
# s/<Abstract> *<AbstractText>/</;
# s/<\/AbstractText> *<\/Abstract>//;
# }
# /MeshHeadingList/{
# s/ *<MeshHeading> *<Descriptor[^>]*>//g;
# s/\(<\/DescriptorName>\|<\/QualifierName>\) *\(<Qualifier[^>]*>\|<\/MeshHeading>\)/, /g;
# s/<MeshHeadingList>/</;
# s/\(, *\|\)<\/MeshHeadingList>//;
# }' $CSV
# inserir a linha de cabeçalho no arquivo
sed
-i
'1i version+pmid<title<abstract<keywords'
$CSV
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment