Sed Help (Using expression - line break)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sed Help (Using expression - line break)
# 1  
Old 02-16-2007
Sed Help (Using expression - line break)

*Note, I thought I was in Shell Programming and Scripting Q&A and posted in a wrong forum. To avoid confusion and to inform people that I'm not trying to "spam" the forums, I'm adding this note up top*

Hi Everyone thanks in advance for any input you can provide on the following question! I'm currently working on AIX 5.3 and almost done with an audit script. I was given some more information from the admins today and I'm able to go back to a function that was semi-complete and expand it out some more. I'm working through the /etc/security/user file:

Within the script already I'm using a sed command to print out a file between 2 expressions:

cat /etc/security/user | awk '{print $1 $2 $3 ", "}' | sed -n '/default:/,/pwdchecks/p' | egrep 'histsize|loginretries|maxage|minlen|pwdwarntime'

This works well and fine for the user known as default, but if I need to run this on several different users (not just "default"), the second expression (the "pwdchecks") isn't always in the same spot for the given information. Here is an example in simpler terms:

The Setup:
Let's say I have information like so:

###BEGIN EXAMPLE INFORMATION###
AUser
AProperty1
AProperty2
AProperty3

BUser
BProperty2
BProperty3
BProperty1
###END EXAMPLE INFORMATION###

cat "filename" | awk '{print $1 $2 $3 ", "}' | sed -n '/user/,/property2/p'

Would give me AUser-AProperty2 but BUser-BProperty2 would only yield me those 2 lines, and not Property1 which I would need.

The Question:
What is the value I need to put where property2 is above and replace it so that the sed will go from "user" until it hits a "line break"?

By doing that, I'll always get the information for the User, it's properties and nothing will ever be missed? Does such a value for "line break" exist?
Thanks in advance for your input.
# 2  
Old 02-16-2007
^$

I did a lot more research and found that if I used ^$, it'll print up and through the last line and blank line that follows thereafter

cat /etc/security/user | sed -n '/root:/,/^$/p'

My apologies again for the board spam, it wasn't meant to be that way...
# 3  
Old 02-16-2007
Quote:
Originally Posted by Janus
My apologies again for the board spam, it wasn't meant to be that way...
Don't worry about that, you made clear in all of them what was intended; there were no posts in the accidental ones as a result, and I deleted them.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed , awk script for printing matched line before regular expression

hi All , I am having a large file with lots of modules as shown below ############################################### module KKK kksd kskks jsn;lsm jsnlsn; Ring jjsjsj kskmsm jjs endmodule module llll 1kksd11 k232skks j33sn;l55sm (6 Replies)
Discussion started by: kshitij
6 Replies

2. Shell Programming and Scripting

How to break the line to the one above?

Hello everyone! I'm trying to make the below file1 look like file2, can anyone help? Basically I just hit backspace on every line that starts with a number. Thanks! file1: THIS#IS-IT1 4 THIS#IS-IT2 3 THIS#IS-IT3 2 THIS#IS-IT4 1 Result > file2: (4 Replies)
Discussion started by: demmel
4 Replies

3. UNIX for Advanced & Expert Users

sed: -e expression #1, char 0: no previous regular expression

Hello All, I'm trying to extract the lines between two consecutive elements of an array from a file. My array looks like: problem_arr=(PRS111 PRS213 PRS234) j=0 while } ] do k=`expr $j + 1` sed -n "/${problem_arr}/,/${problem_arr}/p" problemid.txt ---some operation goes... (11 Replies)
Discussion started by: InduInduIndu
11 Replies

4. UNIX for Dummies Questions & Answers

VI Line Break?

So I'm in a Unix class and our assignment was to go into VI and write a script to make this file tree. At the end of it, I'd like it to echo "This is the file tree you've created" then a line break, then . But I'm not sure as to who to do it. Is there a way for when I run it (./filesystem), the... (4 Replies)
Discussion started by: bbowers
4 Replies

5. Shell Programming and Scripting

sed with line break

<td> CIS </td>and I tried to sed 's/<td>\/nCIS\/n<\/td>/<td><\/td>' and sed 's/<td>\/rCIS\/r<\/td>/<td><\/td>' , but no joy. This is an html page that I need to clean. (4 Replies)
Discussion started by: dba_frog
4 Replies

6. Shell Programming and Scripting

Add line break for each line in a file

I cannot seem to get this to work.. I have a file which has about 100 lines, and there is no end of line (line break \n) at the end of each line, and this is causing problem when i paste them into an application. the file looks like this this is a test that is a test balblblablblhblbha... (1 Reply)
Discussion started by: fedora
1 Replies

7. Shell Programming and Scripting

BASH: Break line, read, break again, read again...

...when the lines use both a colon and commas to separate the parts you want read as information. The first version of this script used cut and other non-Bash-builtins, frequently, which made it nice and zippy with little more than average processor load in GNOME Terminal but, predictably, slow... (2 Replies)
Discussion started by: SilversleevesX
2 Replies

8. Shell Programming and Scripting

sed: break before word if it's not last on the line

I've been trying this, and can't get it right. I want to put a line break before a word, but only if it's *not* the last word in the line. So if the break work was "fish," then... We want to fish tomorrow ...would become... We want to fish tomorrow ...but this line would remain... (3 Replies)
Discussion started by: estebandido
3 Replies

9. Shell Programming and Scripting

TO break a line

hi All, Have a doubt in ksh..Am not familiar with arrays but i have tried out a script.. plzzzzz correct me with the script My i/p File is: (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (Host = 192.168.2.2) (Port = 1525) ) ) (CONNECT_DATA = (SID = TESTDB1) ) ) ... (7 Replies)
Discussion started by: aajan
7 Replies

10. UNIX for Dummies Questions & Answers

SED: How to delete from expression to end of line

I have the following line(s) of text in a file: Card: H'00f2 Elapsed Time (day - h:m:s): 0 - 21:14:18.5 I basically want to search for "Elapsed Time", then delete this and everything else to the end of the line. I've tried a lot of different things, but cannot seem to get rid of... (1 Reply)
Discussion started by: rtstanley
1 Replies
Login or Register to Ask a Question