How to print without authtime?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to print without authtime?
# 1  
Old 11-06-2015
How to print without authtime?

Can someone help me how to print list of "cn" without lastauthtime.
Note: Each cn is separated with blank line.

Code:
Input:

cn=jersey
authtime=2012

cn=mike
authtime=2011

cn=steve

cn=jersey
authtime=2012

cn=rob

cn=matt


Code:
OutPut:

cn=steve
cn=rob
cn=matt

---------- Post updated at 03:26 PM ---------- Previous update was at 03:24 PM ----------

I tried below But its printing in reverse way.
Code:
BEGIN {
        FS="\n"
        RS="\n\n"
        lastauthtime  = ""

}

/lastauthtime/ && NF==2 {
        sub(/user=/,"",$1)
        lastauthtime = lastauthtime " " $1
}

END {
        print "lastauthtime::",lastauthtime
}

---------- Post updated at 04:36 PM ---------- Previous update was at 03:26 PM ----------

Can anyone help me on this?
# 2  
Old 11-06-2015
How about
Code:
awk '/cn=/ {getline X; if (!X) print} ' file
cn=steve
cn=rob
cn=matt

?

---------- Post updated at 22:44 ---------- Previous update was at 22:43 ----------

Or even
Code:
awk '/cn=/ {getline X}  !X ' file
cn=steve
cn=rob
cn=matt

This User Gave Thanks to RudiC For This Post:
# 3  
Old 11-06-2015
Assuming that every segment in your file contains a cn=name line, this might be a little bit simpler (and more portable) to get the output you said you wanted:
Code:
awk 'NF==1' RS= file

Modifying your code so it prints the names of users (if cn=name identifies a user's name) that do not have an authtime=year entry (although naming the variable that contains that list lastauthtime is not at all descriptive), you could try:
Code:
awk '
BEGIN {
        FS="\n"
        RS=""
}

NF==1 {
        sub(/cn=/,"",$1)
        lastauthtime = lastauthtime " " $1
}

END {
        print "lastauthtime::" lastauthtime
}' file

which produces the output:
Code:
lastauthtime:: steve rob matt

Or, more simply (and, perhaps, with less confusing names):
Code:
awk '
BEGIN {
	FS = "="
        RS = ""
}

NF==2 {
        noauthtime = noauthtime " " $2
}

END {
        print "noauthtime::" noauthtime
}' file

which produces the output:
Code:
noauthtime:: steve rob matt

As always, if you want to use any of these scripts on a Solaris/SunOS system, change awk in these scripts to /usr/xpg4/bin/awk or nawk.
This User Gave Thanks to Don Cragun For This Post:
# 4  
Old 11-06-2015
Just for fun:
Code:
(cat file;echo "") | sed -n -e '/^cn=/h;/^authtime=/{n;b};/^$/{x;p}'

This User Gave Thanks to cjcox For This Post:
# 5  
Old 11-07-2015
Hi.

Using a new utility sift (here written as gogrep to avoid a name collision at our site):
Code:
#!/usr/bin/env bash

# @(#) s1	Demonstrate conditional matching, gogrep.
# For "sift" (aka "gogrep" here), see:
# https://sift-tool.org/

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
LC_ALL=C ; LANG=C ; export LC_ALL LANG
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C gogrep

FILE=${1-data1}

pl " Input data file $FILE:"
cat $FILE

pl " Results:"
gogrep --not-followed-within="1:authtime" "cn=" $FILE

exit 0

producing:
Code:
$ ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian 5.0.8 (lenny, workstation) 
bash GNU bash 3.2.39
gogrep sift 0.4.1 (linux/amd64)

-----
 Input data file data1:
cn=jersey
authtime=2012

cn=mike
authtime=2011

cn=steve

cn=jersey
authtime=2012

cn=rob

cn=matt

-----
 Results:
cn=steve
cn=rob
cn=matt

In addition to flexibility, sift is impressively fast.

Best wishes ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Setting up Solaris 10 to print to a windows print server

Guys, I have a issue that I am trying to rectify please advise. lpstat -t shows scheduler is running printer lext644 disabled since Mon Dec 02 19:48:18 2013. available.I have restarted the printer service and it shows online but the above says disabled. I have a lot of jobs in the print... (1 Reply)
Discussion started by: terrywhitejr
1 Replies

2. UNIX for Dummies Questions & Answers

How to create a print filter that print text & image?

Currently, I have a print filter that takes a text file, that convert it into PCL which then gets to a HP printer. This works. Now I need to embedded a image file within the text file. I'm able to convert the image file into PCL and I can cat both files together to into a single document... (1 Reply)
Discussion started by: chedlee88-1
1 Replies

3. UNIX for Advanced & Expert Users

[Solved] remove all print jobs from a print queue

Hello, Sometimes i need to clear all the jobs of a print queue and it is really annoying to cancel one by one. Is there a way to cancel all print jobs for a specific print queue with a single command instead of cancelling them one by one? My AIX system is 5.3 Thank you for your attention (2 Replies)
Discussion started by: omonoiatis9
2 Replies

4. Shell Programming and Scripting

print first few lines, then apply regex on a specific column to print results.

abc.dat tty cpu tin tout us sy wt id 0 0 7 3 19 71 extended device statistics r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device 0.0 133.2 0.0 682.9 0.0 1.0 0.0 7.2 0 79 c1t0d0 0.2 180.4 0.1 5471.2 3.0 2.8 16.4 15.6 15 52 aaaaaa1-xx I want to skip first 5 line... (4 Replies)
Discussion started by: kchinnam
4 Replies

5. Shell Programming and Scripting

print lines AFTER lines cointaining a regexp (or print every first and fourth line)

Hi all, This should be very easy but I can't figure it out... I have a file that looks like this: @SRR057408.1 FW8Y5CK02R652T length=34 AGCAGTGGTATCAACGCAGAGTAAGCAGTGGTAT +SRR057408.1 FW8Y5CK02R652T length=34 FIIHFF6666?=:88@@@BBD:::?@ABBAAA>8 @SRR057408.2 FW8Y5CK02TBMHV length=52... (1 Reply)
Discussion started by: kmkocot
1 Replies

6. Shell Programming and Scripting

Howto Print File Path or Print the Filename

I'm trying to clean up my samba share and need to print the found file or print the path of the image it tried to searched for. So far I have this but can't seem to get the logic right. Can anyone help point me in the right direction? for FILE in `cat list`; do if ; then ... (1 Reply)
Discussion started by: overkill
1 Replies

7. Solaris

Print to ps2pdf print queue

I am trying to create a printer queue, on a SunOS 5.7 system, that outputs a pdf file. There is an application running on the system that has a print button, which sends print files to the default printer. If I disable the printer, I am able to manually capture the files in /var/spool/lp/tmp and... (2 Replies)
Discussion started by: Sean_69
2 Replies

8. UNIX for Dummies Questions & Answers

Print to a ps2pdf print queue.

I am trying to create a printer queue, on a SunOS 5.7 system, that outputs a pdf file. There is an application running on the system that has a print button, which sends print files to the default printer. If I disable the printer, I am able to manually capture the files in /var/spool/lp/tmp and... (1 Reply)
Discussion started by: Sean_69
1 Replies

9. HP-UX

Print Problem in UNIX. Need to know the option to specify the print paper size

Hi, Could any one please let me know what is the option available in UNIX to print by specifying the paper size? We are using Unix11i. I could n't see any option specified in the 'lp' command to print the report by specifying the size of the paper. It would be of great help to me, if... (1 Reply)
Discussion started by: ukarthik
1 Replies

10. Shell Programming and Scripting

How do I get awk to print a " in it's print part?

The line is simple, use " '{ print $1"]"$2"\"$3THE " NEEDS TO GO HERE$4 }' I've tried \", "\, ^" and '"" but none of it works. What am I missing? Putting in the [ between $1 and $2 works fine, I just need to do the same with a ". Thanks. (2 Replies)
Discussion started by: LordJezo
2 Replies
Login or Register to Ask a Question