Sponsored Content
Full Discussion: awk and &&
Top Forums Shell Programming and Scripting awk and && Post 302924575 by sudo on Monday 10th of November 2014 05:46:37 PM
Old 11-10-2014
awk and &&

Hello Everybody.

I am having trouble matching multiple strings within an instanza. I ONLY want it to print if it finds both strings within the range. Example input (newlines between groups inserted only for readibility):

Keywords to match are "artist" and "play count"
Code:
startgroup1
artist: beethoven
album: greatest hits
play count: 30
endgroup

startgroup2
artist: bach
album: the essentials
play count: 23
endgroup

startgroup3
artist: george
album: the lost recordings
endgroup

And the desired output is:
Code:
artist: beethoven
play count: 30
artist: bach
play count: 23

Notice it skipped the 3rd group because it did not have both matches. I have little experience with AWK but I tried to mash solutions together like
Code:
awk '/startgroup*/,/endgroup/ {if(/artist*|play*/) {print}}'

^ which works but it includes group 3. I could not figure out how to insert the && operator instead of the "|", which I assume is what needs to happen.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk: Version && nextfile

How can I find which version of Awk is installed? OpSystem is HPUX 11.x I am getting an error when trying to use the keyword nextfile and I dont know why! (Well, I can only assume that I have am using a version of Awk that does not support nextfile. However, according to O'Reilly, nextfile is... (3 Replies)
Discussion started by: google
3 Replies

2. UNIX for Dummies Questions & Answers

Problem with xterm & tcsh & sourcing a script in a single command

Hi friends, I have a script that sets the env variable path based on different conditions. Now the new path variable setting should not done in the same terminal or same shell. Only a new terminal or new shell should have the new path env variable set. I am able to do this only as follows: >cd... (1 Reply)
Discussion started by: sowmya005
1 Replies

3. Shell Programming and Scripting

Find & Replace string in multiple files & folders using perl

find . -type f -name "*.sql" -print|xargs perl -i -pe 's/pattern/replaced/g' this is simple logic to find and replace in multiple files & folders Hope this helps. Thanks Zaheer (0 Replies)
Discussion started by: Zaheer.mic
0 Replies

4. Shell Programming and Scripting

PHP read large string & split in multidimensional arrays & assign fieldnames & write into MYSQL

Hi, I hope the title does not scare people to look into this thread but it describes roughly what I'm trying to do. I need a solution in PHP. I'm a programming beginner, so it might be that the approach to solve this, might be easier to solve with an other approach of someone else, so if you... (0 Replies)
Discussion started by: lowmaster
0 Replies

5. Shell Programming and Scripting

awk and &&

Hi I need to make some checks inside an awk statement, but cannot come up with the the syntax for several checks under one awk statement, for example: grep -w ${bits} mydata | awk '{if ($3==1)&&($4==3)&&($5==1) print }' awk: syntax error near line 1 awk: illegal statement near line 1 In... (3 Replies)
Discussion started by: aoussenko
3 Replies

6. Shell Programming and Scripting

replace & with & xml file

Hello All I have a xml file with many sets of records like this <mytag>mydata</mytag> <tag2>data&</tag2> also same file can be like this <mytag>mydata</mytag> <tag2>data&</tag2> <tag3>data2&amp;data3</tag3> Now i can grep & and replace with &amp; for whole file but it will replace all... (4 Replies)
Discussion started by: lokaish23
4 Replies

7. Shell Programming and Scripting

Replace & sign to &amp word

Hi, I have text file abc.txt. In this file, I have the following data. Input: Mr Smith &amp Mrs Smith Mr Smith &apos Mrs Smith Mr Smith & Mrs Smith Mr Smith& Mrs Smith Mr Smith &Mrs Smith Output: Mr Smith &amp Mrs Smith Mr Smith &apos Mrs Smith Mr Smith &amp Mrs Smith Mr Smith&amp... (4 Replies)
Discussion started by: naveed
4 Replies

8. Shell Programming and Scripting

Sort a the file & refine data column & row format

cat file1.txt field1 "user1": field2:"data-cde" field3:"data-pqr" field4:"data-mno" field1 "user1": field2:"data-dcb" field3:"data-mxz" field4:"data-zul" field1 "user2": field2:"data-cqz" field3:"data-xoq" field4:"data-pos" Now i need to have the date like below. i have just... (7 Replies)
Discussion started by: ckaramsetty
7 Replies

9. Shell Programming and Scripting

awk Help: quick and easy question may be: How to use &&

Hi Guru's. I am trying to use to check if $5 is greater than 80 & if not 100, then to print $0 : awk '{ if ($5>80) && if ($5 != 100) print $0} But getting error: >bdf1|sed 's/%//g'|awk '{ if ($5>80) && if ($5 != 100) print $0}' syntax error The source line is 1. The error... (6 Replies)
Discussion started by: rveri
6 Replies

10. Shell Programming and Scripting

SFTP Shell Script Get & Delete && Upload & Delete

Hi All, Do you have any sample script, - auto get file from SFTP remote server and delete file in remove server after downloaded. - only download specify filename - auto upload file from local to SFTP remote server and delete local folder file after uploaded - only upload specify filename ... (3 Replies)
Discussion started by: weesiong
3 Replies
PLAIT(1)							   User Commands							  PLAIT(1)

NAME
Plait - Command-line Jukebox. DESCRIPTION
Usage is: "plait <hint about artist or album or song> [[not] <hint>]...[as <mix>]", or "plait --stream <hint> [[not] <hint>]..." OPTIONS
--list,-l -- show matching tracks but don't play --mix,-m -- play tracks matching any hint (make a mix) --queue,-q -- add tracks to queue --random,-r -- play in random order --sort -- play in sorted order --stripe -- play in alternating order --stripe2 -- play in random alternating order --fade -- play in gaussian fade order --group -- play randomly in groups --tracks,-t -- play n tracks, if possible --stream,-s -- play Shoutcast radio streams --mixfile,-f -- read hints from mixfile --device,-d -- choose target device --platform -- choose platform --coverart -- cover art mode (0 or 1) --guest,-g -- use guest configuration --interactive,-i -- interactive mode --cache,-c -- rebuild cache --install -- install Plait --uninstall -- uninstall Plait --play --pause --stop --next --prev --help -- show help --version -- show version AUTHOR
Written by Stephen Jungels (http://stephenjungels.com/contact) COPYRIGHT
Copyright (C) 2005-2008 by Stephen Jungels. Released under the GPL. Latest version and more info at http://plait.sourceforge.net/ Plait v 1.6.2 September 2008 PLAIT(1)
All times are GMT -4. The time now is 04:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy