Discussion:
[awk] Как вычленить закавыченную подстроку, содержащую пробел, из строки?
(too old to reply)
Źmicier)
2010-10-29 19:20:18 UTC
Permalink
åÓÔØ ÓÔÒÏËÁ, ËÏÔÏÒÁÑ ÓÏÄÅÒÖÉÔ ÉÍÅÎÁ ÆÁÊÌÏ×, ÒÁÚÄÅÌÅÎÎÙÅ ÐÒÏÂÅÌÁÍÉ.
åÓÌÉ ÉÍÑ ÆÁÊÌÁ ÓÏÄÅÒÖÉÔ ÐÒÏÂÅÌÙ ? ÏÎÏ ÚÁËÁ×ÙÞÅÎÏ. ô.Å. ËÁË-ÔÏ ÔÁË:
"file 1" file2 file3 "file 4" file5

îÕÖÎÏ ×ÙÞÌÅÎÉÔØ ÉÍÑ ÆÁÊÌÁ ÐÏ ÎÏÍÅÒÕ × ÓÔÒÏËÅ. åÓÌÉ ÅÅ ÐÅÒÅÄÁÔØ
ÂÁÛÅ×ÓËÏÍÕ ÓËÒÉÐÔÕ ÐÁÒÁÍÅÔÒÏÍ ? ×ÓÅ ÐÒÅËÒÁÓÎÏ:

$ cat quot.sh
#!/bin/bash
echo $1

$ ./quot.sh "file 1" file2 file3 "file 4" file5
file 1

á ×ÏÔ ÓÄÅÌÁÔØ ÜÔÏ ÖÅ ÂÅÚ ÓÏÚÄÁÎÉÑ ÏÔÄÅÌØÎÏÇÏ ÓËÒÉÐÔÁ ÎÅ ÐÏÌÕÞÁÅÔÓÑ:

$ echo "file 1" file2 file3 "file 4" file5 | awk '{print $1}'
file

$ echo '"file 1" file2 file3 "file 4" file5' | awk '{print $1}'
"file

$ echo "file 1" file2 file3 "file 4" file5 | (read a b c d e; echo $a)
file

éÎÔÕÉÃÉÑ ÐÏÄÓËÁÚÙ×ÁÅÔ ÍÎÅ, ÞÔÏ ÅÓÔØ ÐÒÏÓÔÏÅ ÒÅÛÅÎÉÅ, Á Ñ Ï ÎÅÍ ÐÒÏÓÔÏ
ÎÅ ÚÎÁÀ. ðÏÄÓËÁÖÉÔÅ, ÐÏÖÁÌÕÊÓÔÁ.
alsmirn ÎÁ gmail.com (Alexey Smirnov)
2010-10-29 19:38:54 UTC
Permalink
Post by Źmicier)
åÓÔØ ÓÔÒÏËÁ, ËÏÔÏÒÁÑ ÓÏÄÅÒÖÉÔ ÉÍÅÎÁ ÆÁÊÌÏ×, ÒÁÚÄÅÌÅÎÎÙÅ ÐÒÏÂÅÌÁÍÉ.
"file 1" file2 file3 "file 4" file5
èÍ, É ÐÒÁ×ÄÁ ÎÅ ÓÏ×ÓÅÍ ÐÏÎÑÔÎÏ ËÁË Ë ÜÔÏÍÕ ÐÏÄÈÏÄÉÔØ.
ëÏÎÅÞÎÏ, ÂÙÌÏ ÂÙ ÐÒÅËÒÁÓÎÏ, ÅÓÌÉ ÂÙ ÎÁ ÎÏ×ÏÊ ÓÔÒÏËÅ ÂÙÌÏ ÎÁÚ×ÁÎÉÅ ÆÁÊÌÁ ;).
--
Alexey Smirnov

alsmirn.moikrug.ru [ru]
linkedin.com/in/alsmirn [en]
alsmirn ÎÁ gmail.com (Alexey Smirnov)
2010-10-29 19:49:08 UTC
Permalink
29 ÏËÔÑÂÒÑ 2010šÇ. 23:38 ÐÏÌØÚÏ×ÁÔÅÌØ Alexey Smirnov
Post by alsmirn ÎÁ gmail.com (Alexey Smirnov)
Post by Źmicier)
åÓÔØ ÓÔÒÏËÁ, ËÏÔÏÒÁÑ ÓÏÄÅÒÖÉÔ ÉÍÅÎÁ ÆÁÊÌÏ×, ÒÁÚÄÅÌÅÎÎÙÅ ÐÒÏÂÅÌÁÍÉ.
"file 1" file2 file3 "file 4" file5
èÍ, É ÐÒÁ×ÄÁ ÎÅ ÓÏ×ÓÅÍ ÐÏÎÑÔÎÏ ËÁË Ë ÜÔÏÍÕ ÐÏÄÈÏÄÉÔØ.
ëÏÎÅÞÎÏ, ÂÙÌÏ ÂÙ ÐÒÅËÒÁÓÎÏ, ÅÓÌÉ ÂÙ ÎÁ ÎÏ×ÏÊ ÓÔÒÏËÅ ÂÙÌÏ ÎÁÚ×ÁÎÉÅ ÆÁÊÌÁ ;).
èÏÔÑ, ÞÅÇÏ ÔÕÔ ÎÅÐÏÎÑÔÎÏÇÏ:
alexey ÎÁ darkstar:~$ cat test.awk
#!/usr/bin/awk -f
BEGIN{
for (a in ARGV) {print ARGV[a]};
}

alexey ÎÁ darkstar:~$ ./test.awk "file 1" file2 file3 "file 4" file5
file 4
file5
awk
file 1
file2
file3

É ×ÐÉÒ£Ô!
--
Alexey Smirnov

alsmirn.moikrug.ru [ru]
linkedin.com/in/alsmirn [en]
Źmicier)
2010-10-29 20:09:33 UTC
Permalink
þÔÏ ÜÔÏ? O_O ðÏÞÅÍÕ ÏÎÏ ÉÍÅÎÎÏ × ÜÔÏÍ ÐÏÒÑÄËÅ É ÏÔËÕÄÁ ÔÁÍ ÐÕÎËÔ ?awk??

29 ÏËÔÑÂÒÑ 2010šÇ. 23:49 ÐÏÌØÚÏ×ÁÔÅÌØ Alexey Smirnov
Post by alsmirn ÎÁ gmail.com (Alexey Smirnov)
29 ÏËÔÑÂÒÑ 2010šÇ. 23:38 ÐÏÌØÚÏ×ÁÔÅÌØ Alexey Smirnov
Post by alsmirn ÎÁ gmail.com (Alexey Smirnov)
Post by Źmicier)
åÓÔØ ÓÔÒÏËÁ, ËÏÔÏÒÁÑ ÓÏÄÅÒÖÉÔ ÉÍÅÎÁ ÆÁÊÌÏ×, ÒÁÚÄÅÌÅÎÎÙÅ ÐÒÏÂÅÌÁÍÉ.
"file 1" file2 file3 "file 4" file5
èÍ, É ÐÒÁ×ÄÁ ÎÅ ÓÏ×ÓÅÍ ÐÏÎÑÔÎÏ ËÁË Ë ÜÔÏÍÕ ÐÏÄÈÏÄÉÔØ.
ëÏÎÅÞÎÏ, ÂÙÌÏ ÂÙ ÐÒÅËÒÁÓÎÏ, ÅÓÌÉ ÂÙ ÎÁ ÎÏ×ÏÊ ÓÔÒÏËÅ ÂÙÌÏ ÎÁÚ×ÁÎÉÅ ÆÁÊÌÁ ;).
alexey ÎÁ darkstar:~$ cat test.awk
#!/usr/bin/awk -f
BEGIN{
š šfor (a in ARGV) {print ARGV[a]};
}
alexey ÎÁ darkstar:~$ ./test.awk "file 1" file2 file3 "file 4" file5
file 4
file5
awk
file 1
file2
file3
É ×ÐÉÒ£Ô!
--
Alexey Smirnov
alsmirn.moikrug.ru [ru]
linkedin.com/in/alsmirn [en]
--
ubuntu-ru mailing list
ubuntu-ru ÎÁ lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-ru
alsmirn ÎÁ gmail.com (Alexey Smirnov)
2010-10-29 20:22:25 UTC
Permalink
Post by Źmicier)
þÔÏ ÜÔÏ? O_O ðÏÞÅÍÕ ÏÎÏ ÉÍÅÎÎÏ × ÜÔÏÍ ÐÏÒÑÄËÅ É ÏÔËÕÄÁ ÔÁÍ ÐÕÎËÔ ?awk??
÷ ÔÁËÏÍ ÐÏÒÑÄËÅ, ÐÏÔÏÍÕ, ÞÔÏ ARGV ÅÓÔØ ÍÁÓÓÉ× ÚÎÁÞÅÎÉÊ, Ó ËÏÔÏÒÙÍ
ÍÏÖÎÏ ÒÁÂÏÔÁÔØ ÐÏ-ÒÁÚÎÏÍÕ.
íÏÖÎÏ É ÔÁË:
#!/usr/bin/awk -f
BEGIN{
i = 0;
while (i < ARGC) {print ARGV[i]; i++;}
}
alexey ÎÁ darkstar:~$ ./test.awk "file 1" file2 file3 "file 4" file5
awk
file 1
file2
file3
file 4
file5

á awk ÔÁÍ ÐÏÔÏÍÕ, ÞÔÏ ÜÔÏ ÔÏÖÅ ÐÁÒÁÍÅÔÒ ËÏÍÁÎÄÎÏÊ ÓÔÒÏËÉ; ×Ù
ËÏÇÄÁ-ÎÉÂÕÄØ ÐÁÒÁÍÅÔÒÙ ËÏÍÁÎÄÎÏÊ ÓÔÒÏËÉ ÎÁ ËÁËÏÍ-ÎÉÂÕÄØ ÑÚÙËÅ
ÒÁÚÂÉÒÁÌÉ?
--
Alexey Smirnov

alsmirn.moikrug.ru [ru]
linkedin.com/in/alsmirn [en]
Źmicier)
2010-10-29 20:53:55 UTC
Permalink
äÁ, ÜÔÏ ÐÏÎÑÔÎÏ, ÉÚ×ÉÎÉÔÅ, ×ÙÒÁÚÉÌ ÕÄÉ×ÌÅÎÉÅ ÒÁÎØÛÅ, ÞÅÍ ÐÏÄÕÍÁÌ. þÔÏ
?awk? Ó ÔÏÞËÉ ÚÒÅÎÉÑ ÛÅÌÌÁ ? ÜÔÏ $0, ÔÏÖÅ ÑÓÎÏ.
ïÄÎÁËÏ ÏÔ ÒÁÂÏÔÙ Ó ÁÒÇÕÍÅÎÔÁÍÉ ËÏÍÓÔÒÏËÉ ÈÏÔÅÌÏÓØ ÂÙ ÉÚÂÁ×ÉÔØÓÑ ×Ï×ÓÅ,
ÐÏÓËÏÌØËÕ ÉÓÈÏÄÎÙÅ ÓÔÒÏËÉ (ÉÈ ÍÎÏÇÏ) ÚÁÐÉÓÁÎÙ × ÆÁÊÌÅ.
á ÐÏÌÑ × ÚÁÐÉÓÉ awk ÄÅÌÉÔ, ÉÇÎÏÒÉÒÕÑ ËÁ×ÙÞËÉ.

ðÏÓËÏÌØËÕ ËÏÍÁÎÄÎÕÀ ÓÔÒÏËÕ ÎÁ ÐÁÒÁÍÅÔÒÙ ÄÅÌÉÔ, ÁÆÁÊË, ÛÅÌÌ, ÍÎÅ
ÐÏÄÕÍÁÌÏÓØ, ÞÔÏ Õ ÎÅÇÏ ÓÕÝÅÓÔ×ÕÅÔ ×ÓÔÒÏÅÎÎÁÑ ËÏÍÁÎÄÁ, ËÏÔÏÒÁÑ
ÐÏÚ×ÏÌÑÅÔ ÜÔÏ ÄÅÌÁÔØ Ó ÌÀÂÏÊ ÓÔÒÏËÏÊ. ÷ ÂÁÛÅ ÅÓÔØ ËÏÍÁÎÄÁ read. èÏÔÅÌ
ÐÏÞÉÔÁÔØ ÍÁÎ ÐÏ ÎÅÊ, ÎÏ ÎÅ ÐÏÌÕÞÉÌÏÓØ ? man read ÒÁÓÓËÁÚÙ×ÁÅÔ Ï ÞÅÍ-ÔÏ
ÄÒÕÇÏÍ.
Post by alsmirn ÎÁ gmail.com (Alexey Smirnov)
Post by Źmicier)
þÔÏ ÜÔÏ? O_O ðÏÞÅÍÕ ÏÎÏ ÉÍÅÎÎÏ × ÜÔÏÍ ÐÏÒÑÄËÅ É ÏÔËÕÄÁ ÔÁÍ ÐÕÎËÔ ?awk??
÷ ÔÁËÏÍ ÐÏÒÑÄËÅ, ÐÏÔÏÍÕ, ÞÔÏ ARGV ÅÓÔØ ÍÁÓÓÉ× ÚÎÁÞÅÎÉÊ, Ó ËÏÔÏÒÙÍ
ÍÏÖÎÏ ÒÁÂÏÔÁÔØ ÐÏ-ÒÁÚÎÏÍÕ.
#!/usr/bin/awk -f
BEGIN{
š i = 0;
š while (i < ARGC) {print ARGV[i]; i++;}
}
alexey ÎÁ darkstar:~$ ./test.awk š"file 1" file2 file3 "file 4" file5
awk
file 1
file2
file3
file 4
file5
á awk ÔÁÍ ÐÏÔÏÍÕ, ÞÔÏ ÜÔÏ ÔÏÖÅ ÐÁÒÁÍÅÔÒ ËÏÍÁÎÄÎÏÊ ÓÔÒÏËÉ; ×Ù
ËÏÇÄÁ-ÎÉÂÕÄØ ÐÁÒÁÍÅÔÒÙ ËÏÍÁÎÄÎÏÊ ÓÔÒÏËÉ ÎÁ ËÁËÏÍ-ÎÉÂÕÄØ ÑÚÙËÅ
ÒÁÚÂÉÒÁÌÉ?
--
Alexey Smirnov
alsmirn.moikrug.ru [ru]
linkedin.com/in/alsmirn [en]
--
ubuntu-ru mailing list
ubuntu-ru ÎÁ lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-ru
alsmirn ÎÁ gmail.com (Alexey Smirnov)
2010-10-29 21:06:43 UTC
Permalink
Post by Źmicier)
ðÏÓËÏÌØËÕ ËÏÍÁÎÄÎÕÀ ÓÔÒÏËÕ ÎÁ ÐÁÒÁÍÅÔÒÙ ÄÅÌÉÔ, ÁÆÁÊË, ÛÅÌÌ, ÍÎÅ
ÐÏÄÕÍÁÌÏÓØ, ÞÔÏ Õ ÎÅÇÏ ÓÕÝÅÓÔ×ÕÅÔ ×ÓÔÒÏÅÎÎÁÑ ËÏÍÁÎÄÁ, ËÏÔÏÒÁÑ
ÐÏÚ×ÏÌÑÅÔ ÜÔÏ ÄÅÌÁÔØ Ó ÌÀÂÏÊ ÓÔÒÏËÏÊ. ÷ ÂÁÛÅ ÅÓÔØ ËÏÍÁÎÄÁ read. èÏÔÅÌ
ÐÏÞÉÔÁÔØ ÍÁÎ ÐÏ ÎÅÊ, ÎÏ ÎÅ ÐÏÌÕÞÉÌÏÓØ ? man read ÒÁÓÓËÁÚÙ×ÁÅÔ Ï ÞÅÍ-ÔÏ
ÄÒÕÇÏÍ.
man bash
/read
~4500 ÓÔÒÏËÁ
--
Alexey Smirnov

alsmirn.moikrug.ru [ru]
linkedin.com/in/alsmirn [en]
Źmicier)
2010-10-29 21:20:43 UTC
Permalink
äÅÊÓÔ×ÉÔÅÌØÎÏ! õ ÍÅÎÑ ÐÏÞÅÍÕ-ÔÏ 3212-Ñ. óÐÁÓÉÂÏ. ôÏÌØËÏ ×ÏÔ ÎÉÞÅÇÏ ÍÎÅ
ÐÏÌÅÚÎÏÇÏ Ñ ÔÁÍ ÎÅ ÎÁÛÅÌ, Õ×Ù.
ïÔÐÒÁ×ÌÀÓØ-ËÁ Ñ ÌÕÞÛÅ ÓÐÁÔØ, ÕÔÒÏÍ ÐÏÄÕÍÁÀ ÎÁ Ó×ÅÖÕÀ ÇÏÌÏ×Õ. :)
Post by alsmirn ÎÁ gmail.com (Alexey Smirnov)
Post by Źmicier)
ðÏÓËÏÌØËÕ ËÏÍÁÎÄÎÕÀ ÓÔÒÏËÕ ÎÁ ÐÁÒÁÍÅÔÒÙ ÄÅÌÉÔ, ÁÆÁÊË, ÛÅÌÌ, ÍÎÅ
ÐÏÄÕÍÁÌÏÓØ, ÞÔÏ Õ ÎÅÇÏ ÓÕÝÅÓÔ×ÕÅÔ ×ÓÔÒÏÅÎÎÁÑ ËÏÍÁÎÄÁ, ËÏÔÏÒÁÑ
ÐÏÚ×ÏÌÑÅÔ ÜÔÏ ÄÅÌÁÔØ Ó ÌÀÂÏÊ ÓÔÒÏËÏÊ. ÷ ÂÁÛÅ ÅÓÔØ ËÏÍÁÎÄÁ read. èÏÔÅÌ
ÐÏÞÉÔÁÔØ ÍÁÎ ÐÏ ÎÅÊ, ÎÏ ÎÅ ÐÏÌÕÞÉÌÏÓØ ? man read ÒÁÓÓËÁÚÙ×ÁÅÔ Ï ÞÅÍ-ÔÏ
ÄÒÕÇÏÍ.
man bash
/read
~4500 ÓÔÒÏËÁ
--
Alexey Smirnov
alsmirn.moikrug.ru [ru]
linkedin.com/in/alsmirn [en]
--
ubuntu-ru mailing list
ubuntu-ru ÎÁ lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-ru
Continue reading on narkive:
Loading...