using sed to remove lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting using sed to remove lines
# 1  
Old 08-05-2010
using sed to remove lines

Can somebody explain why my sed command is not working.

I do the folloinwg:

Generates a binary file to /tmp/x1.out
Code:
/usr/lib/sa/sa2 -s 4:00 -e 8:00 -i 3600 -A -o /tmp/x1.out

decodes the file (no problem so far)
Code:
sar -f /tmp/x1.out

When I do this it does not appear to delete the lines from the top of
the file. Why is that.

Code:
sar -f /tmp/x1.out  | sed '2d'

I know this sar command is writing to stdout since when I do this I see the contents of the output in the new file.

Code:
sar -f /tmp/x1.out  1> /tmp/j1.out

Thanks in advance to all who answer this post

Last edited by Scott; 08-05-2010 at 11:49 AM.. Reason: Please use code tags
# 2  
Old 08-05-2010
Not sure what sar is, but this example uses cat to display a text file.

Code:
# cat test
1
2
3
4
5
6

# cat test | sed '2d'
1
3
4
5
6

# cat test | sed '1,2d'
3
4
5
6

# 3  
Old 08-05-2010
Quote:
Originally Posted by Ikon
Not sure what sar is, but this example uses cat to display a text file.

Code:
# cat test
1
2
3
4
5
6
 
# cat test | sed '2d'
1
3
4
5
6
 
# cat test | sed '1,2d'
3
4
5
6

I know that works, you can man sar to see what it does and I know it
writes to stdout as per my test.

This is what the output shoudl look like its just plain text, I have no clue
why this is an issue. I even wrote a 3 line program that does a printf to stdout and piped it to sed and that worked. What's the mystery?

AIX diamond 3 5 000C86CF4C00 08/05/10

System configuration: lcpu=4

04:00:00 %usr %sys %wio %idle
04:20:00 6 6 4 83
04:40:00 0 1 0 99
05:00:00 0 1 0 99
05:20:00 0 1 0 99
05:40:00 0 0 0 99
06:00:00 1 3 0 96
06:20:00 1 5 0 94
06:40:00 0 1 0 99
07:00:00 0 1 0 99
07:20:01 4 2 3 91
07:40:01 4 3 3 90
08:00:00 4 5 2 90

Average 2 2 1 95
# 4  
Old 08-05-2010
Worked on my HP-UX box, but I dont have a file for it to read.

Code:
#   sar -R -d 1 5

HP-UX MyServerName B.11.31 U ia64    08/05/10

08:13:46   device   %busy   avque     r/s     w/s  blks/s  avwait  avserv
08:13:47    disk3    1.00    0.50       0       1      16    0.00    8.66
08:13:48    disk3   13.00    0.50      30       0     480    0.00    4.34
08:13:49  c3t15d0    0.99    0.50       0       2      32    0.00    0.90
            disk3   56.44   67.69       1     143    2295  234.33   28.81
08:13:50    disk3   39.00    3.63       0      76    1118  119.57   38.54
           disk10    1.00    0.50       0       2      18    0.00    0.84
08:13:51

Average     disk3   21.96   41.63       6      44     785  170.89   28.75
Average   c3t15d0    0.20    0.50       0       0       6    0.00    0.90
Average    disk10    0.20    0.50       0       0       4    0.00    0.84

#   sar -R -d 1 5 | sed '2d'


08:14:09   device   %busy   avque     r/s     w/s  blks/s  avwait  avserv
08:14:10    disk3    3.92    0.50       8       1     204    0.00    4.50
08:14:11
08:14:12    disk3    1.00    0.50       0       2      36    0.00    7.92
08:14:13
08:14:14

Average     disk3    1.00    0.50       2       1      49    0.00    5.12

# 5  
Old 08-05-2010
Samething works for me too when I just run the sar command.

I am guessing some how when reading the file they maybe changing
the file descriptor to another number other than stdout or stderr. Could that confuse sed?

I guess I will post this in an IBM specific forum to verify.

If anybody with an AIX box can try my above-mentioned example I would
apprciate it, this will verify if its the sar command. BTW, I am running aix
version 5.3
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove certain lines using sed?

Hi, I am new to unix and i started some scripting recently. Please go through the following script i wrote. #!/bin/sh file='path../tfile' file1='path../tfile1' rmfile='path../test2' C1=1 C2=1 exec 3< $file1 while read LINE1; do read LINE2 <&3 a=$LINE1 b=`expr $LINE2 - 1` ... (1 Reply)
Discussion started by: Subbu123
1 Replies

2. UNIX for Dummies Questions & Answers

How to remove certain lines using sed?

Hi I have the following kind of line sin my file . print ' this is first'. print ' this is firs and next ' ' line continuous '. -- this is entire print line. print ' this is first and next ' ' line continuous and' 'still there now over'. -- this 3lines together a single print line. ... (5 Replies)
Discussion started by: Sivajee
5 Replies

3. Shell Programming and Scripting

Locate and remove lines with sed

Gents, I would like to remove some lines from a big file ( file2). The objetive is to remove all the lines in file2 containing a certain string which are in file data2delete.. file data2delete contens: 2573.0 7260.01 2893.0 7255.01 2903.0 7245.01 2897.0 7255.01 2561.0 7255.01... (6 Replies)
Discussion started by: jiam912
6 Replies

4. Shell Programming and Scripting

Remove a range of lines from a file using sed

Hi I am having some issue editing a file in sed. What I want to do is, in a loop pass a variable to a sed command. Sed should then search a file for a line that matches that variable, then remove all lines below until it reaches a line starting with a constant. I have managed to write a... (14 Replies)
Discussion started by: Andy82
14 Replies

5. Shell Programming and Scripting

grep/sed to remove lines in file

Hi, I have a file with values, file1: BELL-1180-1180-81|577:1017| BELL-1180-1180-81|jm10i-auto-stub1/577:102| BELL-1180-1180-81|jm10i-auto-stub1/577:101| BELL-1180-1180-81|jm10i-auto-stub1/577:1700| BELL-1180-1180-81|jm10i-auto-stub1/577:1699| I need to remove the lines which has... (9 Replies)
Discussion started by: giri_luck
9 Replies

6. Shell Programming and Scripting

SED to remove a line above and lines below.

:confused:Hi All, I need help on removing lines in a text file. Sample file : When there is a match ip for IPAddress in my `cat ip.out`, proceed delete line above until string "Comp" is found. Thank you very much. ---------- Post updated at 12:56 AM ---------- Previous update was... (4 Replies)
Discussion started by: chiewming
4 Replies

7. Shell Programming and Scripting

What's the command to remove empty lines with sed?

3 10 20 10 100 100 10000 Output: 3 10 20 10 100 100 10000 ---------- Post updated at 07:59 AM ---------- Previous update was at 07:56 AM ---------- sed '/^$/d' file doesn't work. (8 Replies)
Discussion started by: cola
8 Replies

8. Shell Programming and Scripting

How to remove lines before and after with awk / sed ?

Hi guys, I need to remove the pattern (ID=180), one line before and four lines after. Thanks. (5 Replies)
Discussion started by: ashimada
5 Replies

9. Shell Programming and Scripting

Using sed to remove lines where field is empty

I was just looking at this post: https://www.unix.com/shell-programming-scripting/22893-delete-multiple-empty-lines.html. and I am looking to achieve the same with sed. So the idea is to delete lines from a file where a certain field has no value. Inputfile: EMID MMDDYY HOURS JOB EMNAME 0241... (4 Replies)
Discussion started by: figaro
4 Replies

10. Shell Programming and Scripting

Sed or Awk to remove specific lines

I have searched the forum for this - forgive me if I missed a previous post. I have the following file: blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah alter table "informix".esc_acct add constraint (foreign key (fi_id) references "informix".fi ... (5 Replies)
Discussion started by: Shoeless_Mike
5 Replies
Login or Register to Ask a Question