![]() |
|
|
#1 |
|
"Mike"
Aug 2002
25·257 Posts |
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... |
|
|
|
|
|
#2 |
|
Aug 2002
72 Posts |
Minor variation with 29 bytes
sed 's/a/a\n/g' a.a|grep -c a |
|
|
|
|
|
#3 |
|
"Mike"
Aug 2002
25×257 Posts |
Very nice!
Who can beat 29 bytes? |
|
|
|
|
|
#4 |
|
Aug 2003
1100002 Posts |
Minor variation with 28 bytes
sed s/a/a\\n/g a.a|grep -c a |
|
|
|
|
|
#5 | |
|
Bamboozled!
"πΊππ·π·π"
May 2003
Down not across
10,753 Posts |
Quote:
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 |
|
|
|
|
|
|
#6 | |
|
Bamboozled!
"πΊππ·π·π"
May 2003
Down not across
10,753 Posts |
Quote:
echo 8 Yes, it is cheating and it is meant as a joke. Don't get too upset. Paul |
|
|
|
|
![]() |
| 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 |