mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Linux

Reply
 
Thread Tools
Old 2004-01-23, 04:44   #1
Xyzzy
 
Xyzzy's Avatar
 
Aug 2002

23×1,051 Posts
Default Shell script puzzle #1

You have a file called a.a

It contains this:

aaaaabbbbb
aaabbb

Make a shell script to count the total numbers of a's in the file...

My answer:

[FONT=Courier New]sed 's/a/a\n/g' a.a|grep a|wc -l[/FONT]

My answer is 32 bytes long, can anyone make an equivalent command that is shorter?

PS - You can only use tools that are ordinarily shipped with Linux...
Xyzzy is offline   Reply With Quote
Old 2004-01-23, 05:22   #2
gowen72
 
Aug 2002

618 Posts
Default

Minor variation with 29 bytes

sed 's/a/a\n/g' a.a|grep -c a
gowen72 is offline   Reply With Quote
Old 2004-01-23, 05:35   #3
Xyzzy
 
Xyzzy's Avatar
 
Aug 2002

20D816 Posts
Default

Very nice!

Who can beat 29 bytes?
Xyzzy is offline   Reply With Quote
Old 2004-01-25, 13:15   #4
aaronl
 
aaronl's Avatar
 
Aug 2003

24×3 Posts
Default

Minor variation with 28 bytes

sed s/a/a\\n/g a.a|grep -c a
aaronl is offline   Reply With Quote
Old 2004-01-26, 09:32   #5
xilman
Bamboozled!
 
xilman's Avatar
 
"๐’‰บ๐’ŒŒ๐’‡ท๐’†ท๐’€ญ"
May 2003
Down not across

256118 Posts
Default

Quote:
Originally Posted by Xyzzy
Very nice!

Who can beat 29 bytes?
tr -dc a<a.a|wc -c

18 bytes, not including terminal newline.

Tested on RedHat 7.2, FreeBSD 4.9 and SFU 3.5

Yes, there are Microsofties who know how to program Unix-like systems.

Paul
xilman is offline   Reply With Quote
Old 2004-01-26, 10:31   #6
xilman
Bamboozled!
 
xilman's Avatar
 
"๐’‰บ๐’ŒŒ๐’‡ท๐’†ท๐’€ญ"
May 2003
Down not across

3·5·743 Posts
Default

Quote:
Originally Posted by Xyzzy
Very nice!

Who can beat 29 bytes?
Six bytes, not including terminal newline.

echo 8

Yes, it is cheating and it is meant as a joke. Don't get too upset.

Paul
xilman is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Connecting to the bash shell in Windows 10 wombatman Software 10 2018-04-09 02:10
Microsoft adds Linux Bash Shell and Ubuntu Binaries to Win10 ewmayer Software 5 2017-07-22 01:52
Gravity Force of a Spherical Shell davieddy Puzzles 29 2012-08-27 12:26
Please take a look my shell Script in Unix tinhnho Programming 2 2005-09-21 20:20
Script for Mac OS X users astatine NFSNET Discussion 2 2004-01-19 13:05

All times are UTC. The time now is 05:16.


Tue Jan 25 05:16:37 UTC 2022 up 185 days, 23:45, 0 users, load averages: 1.28, 1.58, 1.52

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.

โ‰  ยฑ โˆ“ รท ร— ยท โˆ’ โˆš โ€ฐ โŠ— โŠ• โŠ– โŠ˜ โŠ™ โ‰ค โ‰ฅ โ‰ฆ โ‰ง โ‰จ โ‰ฉ โ‰บ โ‰ป โ‰ผ โ‰ฝ โŠ โŠ โŠ‘ โŠ’ ยฒ ยณ ยฐ
โˆ  โˆŸ ยฐ โ‰… ~ โ€– โŸ‚ โซ›
โ‰ก โ‰œ โ‰ˆ โˆ โˆž โ‰ช โ‰ซ โŒŠโŒ‹ โŒˆโŒ‰ โˆ˜ โˆ โˆ โˆ‘ โˆง โˆจ โˆฉ โˆช โจ€ โŠ• โŠ— ๐–• ๐–– ๐–— โŠฒ โŠณ
โˆ… โˆ– โˆ โ†ฆ โ†ฃ โˆฉ โˆช โŠ† โŠ‚ โŠ„ โŠŠ โŠ‡ โŠƒ โŠ… โŠ‹ โŠ– โˆˆ โˆ‰ โˆ‹ โˆŒ โ„• โ„ค โ„š โ„ โ„‚ โ„ต โ„ถ โ„ท โ„ธ ๐“Ÿ
ยฌ โˆจ โˆง โŠ• โ†’ โ† โ‡’ โ‡ โ‡” โˆ€ โˆƒ โˆ„ โˆด โˆต โŠค โŠฅ โŠข โŠจ โซค โŠฃ โ€ฆ โ‹ฏ โ‹ฎ โ‹ฐ โ‹ฑ
โˆซ โˆฌ โˆญ โˆฎ โˆฏ โˆฐ โˆ‡ โˆ† ฮด โˆ‚ โ„ฑ โ„’ โ„“
๐›ข๐›ผ ๐›ฃ๐›ฝ ๐›ค๐›พ ๐›ฅ๐›ฟ ๐›ฆ๐œ€๐œ– ๐›ง๐œ ๐›จ๐œ‚ ๐›ฉ๐œƒ๐œ— ๐›ช๐œ„ ๐›ซ๐œ… ๐›ฌ๐œ† ๐›ญ๐œ‡ ๐›ฎ๐œˆ ๐›ฏ๐œ‰ ๐›ฐ๐œŠ ๐›ฑ๐œ‹ ๐›ฒ๐œŒ ๐›ด๐œŽ ๐›ต๐œ ๐›ถ๐œ ๐›ท๐œ™๐œ‘ ๐›ธ๐œ’ ๐›น๐œ“ ๐›บ๐œ”