1
$ cat /etc/sudoers    
inavg7ey evl0000332,evl0000333,evl0000234,evl0000999,evs99234456,\\
 evl3300987,evl3344567,evlser999,eul000123,evs3300123,evs3300124,\\
(root,jboss,superss) NOPASSWD:ALL

inavgmcn evl0000332,evl0000333,evl0000234,evl0000999=(all,wasadmin,\\
jboss,superss) NOPASSWD:ALL

I want to print inavg7ey user details with second line as well (if any more lines there i want them also).. could anyone help me with this? I've tried this:

awk '/inavg7ey/' /etc/sudoers

but it's displaying only this one:

inavg7ey evl0000332,evl0000333,evl0000234,evl0000999,evs99234456,\

radas
  • 317
  • 1
  • 13
  • 1
    Using `awk` to parse a file that supports continuation lines is going to require knowing what the continuation line looks like and handling that yourself (to do it robustly). You could always just use one of the solutions from [here](http://stackoverflow.com/a/17914105/258523) too. – Etan Reisner Apr 29 '15 at 14:30
  • `awk '/inavg7ey/&&/\\\\$/{print;getline;print}'` –  Apr 29 '15 at 14:33
  • Thanks Champ, now its displaying matching pattern as well – radas Apr 29 '15 at 14:35
  • could you please help me on the same , if more than5 lines added with \\ symbols.. how we print all lines example inavg7ey ramdas,evl0000332,evl0003322,evs2233999,\\ evl3300999,evs3300142,evl2232232,evh334490,evl009o9o,\\ =(root) NOPASSWD:ALL – radas Apr 29 '15 at 14:40
  • `grep -A1 inavg7e7 /etc/sudoers`... – twalberg Apr 29 '15 at 15:34

2 Answers2

0

You should use grep for this. This will print 2 lines after a match

  grep -A2 inavg7ey /etc/sudoers 

--edit--

it all gets easier if you first remove the newline. This will print each user on one line. Ten simply use grep to get the right user

cat /etc/sudoers | sed  ':a;N;$!ba;s/\\\\\n//g'

or

 cat /etc/sudoers | sed  ':a;N;$!ba;s/\\\\\n//g' | grep inavg7ey
Alex
  • 5,759
  • 1
  • 32
  • 47
  • Thanks for your comment, here some part of my query is clearing but what exactly I'm looking is when I trying to get user information using that command displaying ok for this user as expected.. here for other users have more than 3 to 4 lines .. for each user that's not good practice to expand number and obtaining information Clearly What i'm saying is i want to know how many users have sudo access and on how many boxes they have access by using awk , grep Utility its for auditing root and other application users – radas Apr 30 '15 at 18:01
-1

You may use:

awk '/inavg7ey/{c=N}c&&c--' /etc/sudoers

N - here is number of line after match including match

And another one solution:

awk '/navg7ey/,/^$/' /etc/sudoers

awk -may grep between 2 patterns, in your file,
navg7ey - it's first pattern to grep from;
^$ - it's second pattern to grep to (^$ - means empty line)

Laser
  • 6,652
  • 8
  • 54
  • 85
  • Yes, its working.. Superb I can't expect this kind of quick response from you all ... Have a nice day... again Thanks – radas Apr 29 '15 at 14:44
  • a small problem but here when i execute the above command , its showing all lines in a file that contain with other names for example awk '/inavg7ey/{c=9}c&&c--' list [root@dasari9 scripts]# vi list [root@dasari9 scripts]# awk '/inavg7ey/{c=9}c&&c--' list inavg7ey ramdas,evl0000332,evl0003322,evs2233999,\\ evl3300999,evs3300142,evl2232232,evh334490,evl009o9o,\\ =(root) NOPASSWD:ALL inavgmcn evs300132,evl3333333,3vsfjhasad,\\ evl1212123,12312312hh,asdasdasd,\\ =(root) NOPASSWD:ALL I want to see only inavg7ey user details – radas Apr 29 '15 at 14:51
  • 3
    @Ramdas this is why it's important to show us a FEW lines of sample input, not just the segment of file you want extracted. It's always trivial to select the lines you want but much harder to not select the lines you don't want. At this point you haven't shown us anything at all that'd let us figure out a more robust solution or help you debug your current problem. Edit your question to show more useful input/output - providing info in a comment is not useful since it cannot be formatted to match your real file. I strongly suspect what you REALLY want is just to include lines following `\\\`. – Ed Morton Apr 29 '15 at 14:54
  • @Ramdas could you please add these lines to question, because it's absolutely unreadable as comment – Laser Apr 29 '15 at 19:10