Struck at shell command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Struck at shell command
# 1  
Old 11-05-2015
Struck at shell command

Can someone help me to get two different outputs mentioned in code tags.
Input:

Code:
user=alexander
registeredwebsite=yahoo.com

user=james
registeredwebsite=gmail.com
registeredwebsite=fb.com
registeredwebsite=google.com

user=kelly
registeredwebsite=gmail.com
registeredwebsite=fb.com
registeredwebsite=google.com

user=natasha
registeredwebsite=gmail.com
registeredwebsite=fb.com
registeredwebsite=yahoo.com

user=bipasha
registeredwebsite=hotmail.com
registeredwebsite=medicus.com
registeredwebsite=yahoo.com

user=paul
registeredwebsite=yahoo.com

user=mike
registeredwebsite=yahoo.com



Need List of users registered only in yahoo.com website.

Output-1:

Users Registered only on yahoo.com website are:

Code:
user=alexander
user=paul
user=mike

Need list of users registered not only yahoo but also other websites.

Output-2:

Users Registered on yahoo.com but also other websites are:

Code:
user=natasha
user=bipasha

Moderator's Comments:
Mod Comment Surrounding your entire post with ICODE tags is not what is expected. Use CODE tags around sample input, around sample output, and around code segments.

Last edited by Don Cragun; 11-05-2015 at 06:32 PM.. Reason: Fix ICODE tags; add CODE tags.
# 2  
Old 11-05-2015
With all of the help you got on your last request: Need help for count using shell, you must have a good start on a script to do this.

Show us what you have tried, show us the output it produces (both normal output and diagnostic messages).
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 11-05-2015
Hi Don Cragun,

I tried below but it did't worked.
Code:
awk '/pattern/{nr[NR]; nr[NR+4]}; NR in nr' file

Moderator's Comments:
Mod Comment Please use CODE tags when displaying sample input, sample output, and non-HTML code segments.
Only use HTML tags when displaying HTML code segments.

Last edited by Don Cragun; 11-05-2015 at 09:35 PM.. Reason: Change HTML tags to CODE tags.
# 4  
Old 11-05-2015
Code:
[buzzme]$ awk '/yahoo\.com/ && NF==2 {print $1}' RS= buzzme.file
user=alexander
user=paul
user=mike

[buzzme]$ awk '/yahoo\.com/ && NF>2 {print $1}' RS= buzzme.file
user=natasha
user=bipasha

---------- Post updated at 07:44 PM ---------- Previous update was at 06:56 PM ----------

Code:
perl -00 -alne '
    /yahoo\.com/ and push @{$yahoo{scalar @F == 2}}, $F[0];
    END{ print "Yahoo Only:\n", join "\n", @{$yahoo{1}};
         print "Yahoo Plus:\n", join "\n", @{$yahoo{$undef}};
    }
' buzzme.file

Code:
Yahoo Only:
user=alexander
user=paul
user=mike

Yahoo Plus:
user=natasha
user=bipasha

This User Gave Thanks to Aia For This Post:
# 5  
Old 11-06-2015
Small variation:
Code:
awk -F= 'NF==4 && $4=="yahoo.com"{print $2}' RS= file

Code:
alexander
paul
mike

The condition for using RS= (set the RS variable to an empty string) is that the separation between segments must consist of two or more consecutive newlines, nothing else (no extra spaces).

--
Otherwise, try something like:
Code:
awk -F= '$1=="user"{if(n)print n; n=$2; next} NF && $2!="yahoo.com"{n=""} END{if(n)print n}' file

or:
Code:
awk -F= '$1=="user"{if(n)print n; n=$2; next} $1=="registeredwebsite" && $2!="yahoo.com"{n=""} END{if(n)print n}' file


Last edited by Scrutinizer; 11-06-2015 at 01:01 AM..
This User Gave Thanks to Scrutinizer For This Post:
# 6  
Old 11-06-2015
Code:
users={}
mark=[]
with open("a.txt") as file:
	for line in file:
		line=line.replace("\n","")
		if len(line)==0:
			continue
		if 'user=' in line:
			user=line
		else:
			if user in users:
				users[user] += 1
			else:
				users[user] = 1
			if 'yahoo' in line:
				mark.append(user)
print("========not only yahoo=========")
for user in mark:
	if users[user]>1:
		print(user)

print("========yahoo=========")	
for i in mark:
	print(i)
	
print("========only yahoo=========")	
for i in mark:
	if users[i]==1:
		print(i)

Moderator's Comments:
Mod Comment python

Last edited by Scrutinizer; 11-06-2015 at 06:05 PM.. Reason: Add CODE tags. Added "python comment"
This User Gave Thanks to summer_cherry For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Shell script not working but command works in command prompt

Hi everyone I have a problem with my script If I try directly this command /usr/bin/nice -n 19 mysqldump -u root --password="******" wiki_schneider -c | nice -n 19 gzip -9 > /point_de_montage/$(date '+%Y%m%d')-wiki-db.sql.gz It works But if I simply add this command in a script and... (8 Replies)
Discussion started by: picemma
8 Replies

2. UNIX Desktop Questions & Answers

command to run another shell on top of your default shell?

Can someone point me to the right command to to run another shell on top of your default shell? Thanks PS If admin sees this It is not home work. I am old man who wants to learn unix in my spare time. I CURRENTLY DO NOT GO SCHOOL, COLLEGE OR UNIVERSITY. (2 Replies)
Discussion started by: Bill Thompson
2 Replies

3. Shell Programming and Scripting

When i am trying to execute export command within a shell script it is saying command not found.

I am running the export command within a view to use that value inside my build script. But while executing it it is saying "export command not found" My code is as follows: -------------------------- #!/bin/sh user="test" DIR="/bldtmp/"$user VIEW="test.view1" echo "TMPDIR before export... (4 Replies)
Discussion started by: dchoudhury
4 Replies

4. Shell Programming and Scripting

Any shell or hack that makes the shell command line take vi commands?

basically i'm tired of hitting the left arrow a few dozen times when correcting a mistake or modifying a history command i'd like to use vim style key shortcuts while on the command line so that a 55 moves the cursor 55 places to the left... and i want all the other vi goodies, search of... (3 Replies)
Discussion started by: marqul
3 Replies

5. Shell Programming and Scripting

Struck with Typeset Command

Can someone explain whats this below command will do exactly.. typeset tmpFile1 tmpDir1 rc fileName fullName bc typeset tmpFile1 tmpFile2 rc fileSuffix uef typeset origFile bc fullName tmpDir1 remoteCmd inFile newInFile typeset num fn curDate fileSuffix ucFileName Since i'm new to... (1 Reply)
Discussion started by: help_scr_seeker
1 Replies

6. Shell Programming and Scripting

can anyone help with shell script command about searching word with grep command?

i want to search in the current directory all the files that contain one word for example "hello" i want to achieve it with the grep command but not with the grep * (2 Replies)
Discussion started by: aintour
2 Replies

7. Shell Programming and Scripting

Need to Write Shell Script based off of this shell command

I'm trying to read a bunch of log files and output the lines that contain particular strings. To accomplish this, I've been running the following from the command line: find . -name "*" | xargs grep " " | grep " " > output.txt Two grep statements are needed in case I'm looking for a... (3 Replies)
Discussion started by: Rally_Point
3 Replies

8. Shell Programming and Scripting

Awking!! Printing decimal output is struck

Hi friends, I have a small problem with AWK. I am not able to print decimal values! :confused: below is my code: #! /bin/awk -f awk BEGIN{printf("%d",123)}; -> This prints the integer properly. x=111 awk BEGIN{printf("%d",x)}; -> This doesnt print! :( Please help me solve this. It... (4 Replies)
Discussion started by: divzz
4 Replies

9. HP-UX

How to use more than one MPE command STREAM with Unix command in a single shell?

Hello, I have problem in writing the shell script involving MPE command STREAM related to HP-UX and Unix command. Script is sh "nlshCMD 'STREAM <job name1>' | 'SHOWJOB' | grep $HPJOBNUM" sh "nlshCMD 'STREAM <job name2>' | 'SHOWJOB' | grep $HPJOBNUM" sh "nlshCMD 'STREAM <job name3>' |... (1 Reply)
Discussion started by: bosskr
1 Replies

10. Shell Programming and Scripting

How to use more than one MPE command STREAM with Unix command in a single shell?

Hello, I have problem in writing the shell script involving MPE command STREAM related to HP-UX and Unix command. Script is sh "nlshCMD 'STREAM <job name1>' | 'SHOWJOB' | grep $HPJOBNUM" sh "nlshCMD 'STREAM <job name2>' | 'SHOWJOB' | grep $HPJOBNUM" sh "nlshCMD 'STREAM <job name3>' |... (0 Replies)
Discussion started by: bosskr
0 Replies
Login or Register to Ask a Question