TEXT processing with awk [closed]
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
-2
down vote
favorite
I have text like below:
select 112,department,112,client,112,place from table where id=1 and 112,cgid and 113,evid
I need to write into a file as
112,department
112,client
112,place
112,cgid
113,evid
with each item on its own line.
I tried awk -F '[]' 'print $2'
but it prints only the first occurrence and only the data without . Adding suffix and the prefix
gives a syntax error?
Additional requirement
- to replace
va1,val2
in the query with a single value which I'll get after querying a table usingval1
andval2
.
text-processing awk text
closed as unclear what you're asking by steve, Kusalananda, Jesse_b, G-Man, Isaac Jul 27 at 21:34
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
up vote
-2
down vote
favorite
I have text like below:
select 112,department,112,client,112,place from table where id=1 and 112,cgid and 113,evid
I need to write into a file as
112,department
112,client
112,place
112,cgid
113,evid
with each item on its own line.
I tried awk -F '[]' 'print $2'
but it prints only the first occurrence and only the data without . Adding suffix and the prefix
gives a syntax error?
Additional requirement
- to replace
va1,val2
in the query with a single value which I'll get after querying a table usingval1
andval2
.
text-processing awk text
edited Jul 27 at 8:25
answered Jul 27 at 8:20
steve
11.9k22047
11.9k22047
thank u.. this worked but this pattern may occur anywhere in the query.. not only i the select..
â komz
Jul 27 at 9:00
add a comment |Â
thank u.. this worked but this pattern may occur anywhere in the query.. not only i the select..
â komz
Jul 27 at 9:00
thank u.. this worked but this pattern may occur anywhere in the query.. not only i the select..
â komz
Jul 27 at 9:00
thank u.. this worked but this pattern may occur anywhere in the query.. not only i the select..
â komz
Jul 27 at 9:00
add a comment |Â
up vote
0
down vote
With perl
:
perl -lne 'print for /.*?(?=.*from S+ where)/g'
With GNU grep
or compatible:
grep -Po '.*?(?=.*from S+ where)'
With GNU awk
:
gawk -v FPAT='[][][^]*[][}]' '
sub(/from [[:space:]]+ where.*/, "")
for (i = 1; i <= NF; i++) print $i'
For all, you can feed the input on stdin or as a filename argument.
i am sorry. to ask this... how can i specify the input file in the above commands.. i m totally new to this
â komz
Jul 27 at 9:03
Add it as file arg. to them likegrep .... <file>
.
â slmâ¦
Jul 27 at 9:04
perl -lne 'print for /.*?/g' input.hql. am i right ? this didnt work
â komz
Jul 27 at 9:08
For theperl
one do thiscat <file> | perl ...
â slmâ¦
Jul 27 at 9:12
cat input.hql | perl -lne 'print for /.*?/g' this didnt give any o/p.. shd v capture the o/p for display?
â komz
Jul 27 at 9:16
add a comment |Â
up vote
0
down vote
With perl
:
perl -lne 'print for /.*?(?=.*from S+ where)/g'
With GNU grep
or compatible:
grep -Po '.*?(?=.*from S+ where)'
With GNU awk
:
gawk -v FPAT='[][][^]*[][}]' '
sub(/from [[:space:]]+ where.*/, "")
for (i = 1; i <= NF; i++) print $i'
For all, you can feed the input on stdin or as a filename argument.
i am sorry. to ask this... how can i specify the input file in the above commands.. i m totally new to this
â komz
Jul 27 at 9:03
Add it as file arg. to them likegrep .... <file>
.
â slmâ¦
Jul 27 at 9:04
perl -lne 'print for /.*?/g' input.hql. am i right ? this didnt work
â komz
Jul 27 at 9:08
For theperl
one do thiscat <file> | perl ...
â slmâ¦
Jul 27 at 9:12
cat input.hql | perl -lne 'print for /.*?/g' this didnt give any o/p.. shd v capture the o/p for display?
â komz
Jul 27 at 9:16
add a comment |Â
up vote
0
down vote
up vote
0
down vote
With perl
:
perl -lne 'print for /.*?(?=.*from S+ where)/g'
With GNU grep
or compatible:
grep -Po '.*?(?=.*from S+ where)'
With GNU awk
:
gawk -v FPAT='[][][^]*[][}]' '
sub(/from [[:space:]]+ where.*/, "")
for (i = 1; i <= NF; i++) print $i'
For all, you can feed the input on stdin or as a filename argument.
With perl
:
perl -lne 'print for /.*?(?=.*from S+ where)/g'
With GNU grep
or compatible:
grep -Po '.*?(?=.*from S+ where)'
With GNU awk
:
gawk -v FPAT='[][][^]*[][}]' '
sub(/from [[:space:]]+ where.*/, "")
for (i = 1; i <= NF; i++) print $i'
For all, you can feed the input on stdin or as a filename argument.
edited Jul 27 at 9:20
answered Jul 27 at 8:58
Stéphane Chazelas
278k52512842
278k52512842
i am sorry. to ask this... how can i specify the input file in the above commands.. i m totally new to this
â komz
Jul 27 at 9:03
Add it as file arg. to them likegrep .... <file>
.
â slmâ¦
Jul 27 at 9:04
perl -lne 'print for /.*?/g' input.hql. am i right ? this didnt work
â komz
Jul 27 at 9:08
For theperl
one do thiscat <file> | perl ...
â slmâ¦
Jul 27 at 9:12
cat input.hql | perl -lne 'print for /.*?/g' this didnt give any o/p.. shd v capture the o/p for display?
â komz
Jul 27 at 9:16
add a comment |Â
i am sorry. to ask this... how can i specify the input file in the above commands.. i m totally new to this
â komz
Jul 27 at 9:03
Add it as file arg. to them likegrep .... <file>
.
â slmâ¦
Jul 27 at 9:04
perl -lne 'print for /.*?/g' input.hql. am i right ? this didnt work
â komz
Jul 27 at 9:08
For theperl
one do thiscat <file> | perl ...
â slmâ¦
Jul 27 at 9:12
cat input.hql | perl -lne 'print for /.*?/g' this didnt give any o/p.. shd v capture the o/p for display?
â komz
Jul 27 at 9:16
i am sorry. to ask this... how can i specify the input file in the above commands.. i m totally new to this
â komz
Jul 27 at 9:03
i am sorry. to ask this... how can i specify the input file in the above commands.. i m totally new to this
â komz
Jul 27 at 9:03
Add it as file arg. to them like
grep .... <file>
.â slmâ¦
Jul 27 at 9:04
Add it as file arg. to them like
grep .... <file>
.â slmâ¦
Jul 27 at 9:04
perl -lne 'print for /.*?/g' input.hql. am i right ? this didnt work
â komz
Jul 27 at 9:08
perl -lne 'print for /.*?/g' input.hql. am i right ? this didnt work
â komz
Jul 27 at 9:08
For the
perl
one do this cat <file> | perl ...
â slmâ¦
Jul 27 at 9:12
For the
perl
one do this cat <file> | perl ...
â slmâ¦
Jul 27 at 9:12
cat input.hql | perl -lne 'print for /.*?/g' this didnt give any o/p.. shd v capture the o/p for display?
â komz
Jul 27 at 9:16
cat input.hql | perl -lne 'print for /.*?/g' this didnt give any o/p.. shd v capture the o/p for display?
â komz
Jul 27 at 9:16
add a comment |Â
up vote
0
down vote
I'd use grep
rather than awk
. Here the -P
flag asks grep
to use PCRE regular expressions rather than its default (so that .*?
matches as little as possible), and the -o
flag gets grep
to print only matching components:
grep -Po '.*?'
Example:
grep -Po '.*?' <<<'select 112,department,112,client,112,place from table where id=1 and 112,cgid and 113,evid'
112,department
112,client
112,place
112,cgid
113,evid
There is no va1,val2
to match in your query so the "additional requirement" is moot. Or are you generalising to the matched entities such as 112,department
? If so, you need to explain what is to be done, because to replace [them] in the query with a single value which I'll get [later] is too broad a requirement to address with explicit code.
thank u this worked... now how can i capture the first value from . like 112 from 112,department. i tried var1=echo $line | awk -F '[]' 'print $2' | awk -F '[,]' 'print $1'
its not working. the same command works for single
â komz
Aug 1 at 4:21
add a comment |Â
up vote
0
down vote
I'd use grep
rather than awk
. Here the -P
flag asks grep
to use PCRE regular expressions rather than its default (so that .*?
matches as little as possible), and the -o
flag gets grep
to print only matching components:
grep -Po '.*?'
Example:
grep -Po '.*?' <<<'select 112,department,112,client,112,place from table where id=1 and 112,cgid and 113,evid'
112,department
112,client
112,place
112,cgid
113,evid
There is no va1,val2
to match in your query so the "additional requirement" is moot. Or are you generalising to the matched entities such as 112,department
? If so, you need to explain what is to be done, because to replace [them] in the query with a single value which I'll get [later] is too broad a requirement to address with explicit code.
thank u this worked... now how can i capture the first value from . like 112 from 112,department. i tried var1=echo $line | awk -F '[]' 'print $2' | awk -F '[,]' 'print $1'
its not working. the same command works for single
â komz
Aug 1 at 4:21
add a comment |Â
up vote
0
down vote
up vote
0
down vote
I'd use grep
rather than awk
. Here the -P
flag asks grep
to use PCRE regular expressions rather than its default (so that .*?
matches as little as possible), and the -o
flag gets grep
to print only matching components:
grep -Po '.*?'
Example:
grep -Po '.*?' <<<'select 112,department,112,client,112,place from table where id=1 and 112,cgid and 113,evid'
112,department
112,client
112,place
112,cgid
113,evid
There is no va1,val2
to match in your query so the "additional requirement" is moot. Or are you generalising to the matched entities such as 112,department
? If so, you need to explain what is to be done, because to replace [them] in the query with a single value which I'll get [later] is too broad a requirement to address with explicit code.
I'd use grep
rather than awk
. Here the -P
flag asks grep
to use PCRE regular expressions rather than its default (so that .*?
matches as little as possible), and the -o
flag gets grep
to print only matching components:
grep -Po '.*?'
Example:
grep -Po '.*?' <<<'select 112,department,112,client,112,place from table where id=1 and 112,cgid and 113,evid'
112,department
112,client
112,place
112,cgid
113,evid
There is no va1,val2
to match in your query so the "additional requirement" is moot. Or are you generalising to the matched entities such as 112,department
? If so, you need to explain what is to be done, because to replace [them] in the query with a single value which I'll get [later] is too broad a requirement to address with explicit code.
answered Jul 27 at 17:49
roaima
39.2k544105
39.2k544105
thank u this worked... now how can i capture the first value from . like 112 from 112,department. i tried var1=echo $line | awk -F '[]' 'print $2' | awk -F '[,]' 'print $1'
its not working. the same command works for single
â komz
Aug 1 at 4:21
add a comment |Â
thank u this worked... now how can i capture the first value from . like 112 from 112,department. i tried var1=echo $line | awk -F '[]' 'print $2' | awk -F '[,]' 'print $1'
its not working. the same command works for single
â komz
Aug 1 at 4:21
thank u this worked... now how can i capture the first value from . like 112 from 112,department. i tried var1=
echo $line | awk -F '[]' 'print $2' | awk -F '[,]' 'print $1'
its not working. the same command works for single â komz
Aug 1 at 4:21
thank u this worked... now how can i capture the first value from . like 112 from 112,department. i tried var1=
echo $line | awk -F '[]' 'print $2' | awk -F '[,]' 'print $1'
its not working. the same command works for single â komz
Aug 1 at 4:21
add a comment |Â
Is this a typo?
112,cgid and Â