Hi -
I have a file containing data like :-
cn=tommy,cn=users,c=uk
passwordexpirydate=20100530130623z
cn=jane,cn=users,c=uk
passwordexpirydate=20100423140734z
cn=michael,cn=users,c=uk
passwordexpirydate=20100331020044z
I want to end up with a file that looks like:-
cn=tommy,cn=users,c=uk
20100530130623
cn=jane,cn=users,c=uk
20100423140734
cn=michael,cn=users,c=uk
20100331020044
I can very inefficiently first remove the blank lines using something like:-
sed '/^$/d' file1 > file2
I can use awk to just extract the date without the "passwordexpirydate=" and "z".
But what I can not do is do eveything I need to do in one loop .. e.g. using a while read line do ... done loop.
Any ideas please?
Hi,
sed s/^passwordexpirydate=*// IN_FILE| sed '/^$/d' | sed s/z$//
It's sure there is another form in only one sentence....wait for the responses of sed and awk's gurus...
Try:
sed "/^$/d;s/^password[^=]*=\(.*\)z$/\1/" file
HTH Chris
Thanks for the replies. Both answers work perfectly.
---------- Post updated at 03:02 PM ---------- Previous update was at 12:18 PM ----------
This is suddenly got more complicated!!
I need to do what I did before but also delete any line starting cn=users or cn=Users and the following line.
So,
cn=tommy,cn=users,c=uk
passwordexpirydate=20100530130623z
cn=Users,cn=users,c=uk
passwordexpirydate=20100423100000z
cn=jane,cn=users,c=uk
passwordexpirydate=20100423140734z
cn=michael,cn=users,c=uk
passwordexpirydate=20100331020044z
would end up as :-
cn=tommy,cn=users,c=uk
20100530130623
cn=jane,cn=users,c=uk
20100423140734
cn=michael,cn=users,c=uk
20100331020044
Thanks in advance for any help.
anbu23
5
sed "/^$/d;/^cn=Users/{N;d;};s/^password[^=]*=\(.*\)z$/\1/" file
clx
6
Also,
awk -F= '/^cn/ {print} /^passwordexpirydate/ { gsub("z","",$2);print $2}' file
Cheers thanks all for the help.