Visit Our UNIX and Linux User Community


help in finishing 2 commands


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers help in finishing 2 commands
# 1  
Old 01-18-2008
help in finishing 2 commands

the first one:
1.
i am trying to build a command that searches a text file
and outputs the number of words which consists of two 'b' characters
in each word separatly

like
barby

(the b characters must be separated from one another)
i tried to use grep [b][b] filepath
then i know that we need to use pipe to count the result

but it prints all the word with the two b chars
one next to the other

i tried also
fmt -1 file-name | grep '^[^b]+b\{1\}[^b]+b\{1\}[^b]+$' path

didnt work either



the second one is:
i tried to build a command to replaces the word "include" with
"exclude"

in each *.h type of file in a certain directory
and to display the lines in which the switch happened.

i did a command and i dont know why its not working

find /usr -name "*.h" -exec sed 's/include/exclude/g' {} \; |grep exclude
# 2  
Old 01-18-2008
if you know Perl, try this:
Code:
#!/usr/bin/perl
# 2b.pl
while (<>) {
    print if (m/b[^\s]+b/);
}

run it as:
Code:
perl 2b.pl file

# 3  
Old 01-18-2008
i need to have that in unix code,i dont know how..

to switch this code into unix command

i need to make it as unix command
# 4  
Old 01-18-2008
Code:
# awk '/b[^\s]+b/' file
barby

Please read the docs.
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #69
Difficulty: Easy
Grep stands for 'global regular expression process'.
True or False?

9 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Having issues finishing up a few scripting problems. A little help would be awesome

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 4. Recall that the env command provides a list of various environment variables available to you. Two of those... (5 Replies)
Discussion started by: megachuk
5 Replies

2. Shell Programming and Scripting

Need help in finishing a bash script for listing subfolder by size in a large folder

Greetings everyone. I have seen that you do wonders here. I have a large folder on a Ubuntu linux. Organization main folder, inside 20 000 subfolders, and inside those subolders many other like 5-6 folders and files. I am interested to create an output to a txt file under the bash... (2 Replies)
Discussion started by: ultimo
2 Replies

3. UNIX for Advanced & Expert Users

Full System Recursive Search for a String - Not Finishing

Using grep -r -H "foobar" / > result to give all files that contain the string "foobar" Half way , its waiting for some thing and does not end Not Sure whats happening. Any help is much appreciated Thank you (2 Replies)
Discussion started by: shorn
2 Replies

4. Shell Programming and Scripting

Bash script - $(ls expr) return double file name with one finishing with '.'

Hello. This small part of my script #!/bin/bash SRCDIR=/root/.kde4/share/config for MY_FILE in $(ls $SRCDIR/kate*) ; do echo "$MY_FILE" donegive : So for the moment I have modified my script like this : #!/bin/bash SRCDIR=/root/.kde4/share/config for MY_FILE in $(ls... (5 Replies)
Discussion started by: jcdole
5 Replies

5. UNIX for Dummies Questions & Answers

help with some commands

Hi! i'd like from someone to explain me 'what is what' from these parts of code if it's possible.i'd like to understand them and their usage: 1) sed '3d' filename 2) sort –t: +0 -1 /etc/passwd and also this: tr ‘’ ‘ ‘ < filename thank you! (11 Replies)
Discussion started by: strawhatluffy
11 Replies

6. AIX

HACMP: difference between 'cl' commands and 'cli' commands

Hi all, I'm new in this forum. I'm looking for the difference between the HACMP commands with the prefix "cl" and "cli". The first type are under /usr/es/sbin/cluster/sbin directory and the second are under /usr/es/sbin/cluster/cspoc directory. I know that the first are called HACMP for AIX... (0 Replies)
Discussion started by: peppix
0 Replies

7. Shell Programming and Scripting

Can BASH execute commands on a remote server when the commands are embedded in shell

I want to log into a remote server transfer over a new config and then backup the existing config, replace with the new config. I am not sure if I can do this with BASH scripting. I have set up password less login by adding my public key to authorized_keys file, it works. I am a little... (1 Reply)
Discussion started by: bash_in_my_head
1 Replies

8. Programming

code that reads commands from the standard i/p and executes the commands

Hello all, i've written a small piece of code that will read commands from standard input and executes the commands. Its working fine and is execting the commands well. Accepting arguments too. e.g #mkdir <name of the directory> The problem is that its not letting me change the directory i.e... (4 Replies)
Discussion started by: Phrozen Smoke
4 Replies

9. UNIX for Dummies Questions & Answers

commands

where can I find a list of unix commands to study? (4 Replies)
Discussion started by: Rush
4 Replies

Featured Tech Videos