Sed command - help me understand


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sed command - help me understand
# 1  
Old 05-18-2009
Sed command - help me understand

Hello,
can someone please explain me what the following commands do.. i know the output but i would like to understand the break down of what they do step by step.

1) sed -n "/ $(date +\%R -d "-1 min")/,$"p req.txt| wc -l

2)
awk '/19:00/,/22:00/' app.log |grep "mytesturl"|grep ',900,'|awk -F, '{print $1, $6, $10}' | awk '{print $2}'|sed -r 's/:[0-9][0-9]\.[0-9]{3}//g' |sort |uniq -c

i really appreciate the help..

# 2  
Old 05-19-2009
1. This will give the current time minus 1 min in the form of hh:mm
Code:
date +%R -d "-1 min"

This will print the lines begining (line that matches the above hh:mm time) till the end of the line for the file req.txt

Code:
sed -n "/ $(date +\%R -d "-1 min")/,$"p req.txt

This will count the no of lines returned
Code:
 wc -l

so
Code:
sed -n "/ $(date +\%R -d "-1 min")/,$"p req.txt| wc -l

will o/p no of lines.

2. This will print lines between the lines that matches 19:00 and till 22:00
Code:
awk '/19:00/,/22:00/' app.log

From the above lines, it will filter only the lines that contain the string mytesturl

Code:
awk '/19:00/,/22:00/' app.log |grep "mytesturl"

From the returned lines, this will print field no 1,6 and 10 only which are comma seperated
Code:
awk '/19:00/,/22:00/' app.log |grep "mytesturl"|grep ',900,'|awk -F, '{print $1, $6, $10}'

This will print only field 2 from the above lines

Code:
awk '/19:00/,/22:00/' app.log |grep "mytesturl"|grep ',900,'|awk -F, '{print $1, $6, $10}' | awk '{print $2}'

The sed command and sort and uniq:
sed will look for string like :hh.mmm and replace with nothing and its o/p is sorted and then count on the uniq values
# 3  
Old 05-19-2009
thanks..

this was a very good explanation...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help understand awk command

Help understand awk command This command converts the column values to rows. Command: awk -s1=" " '{S=S?S OFS s1 $0 s1:s1 $0 s1} END{print S}' OFS=, Input_file Example: 1 2 3 is converted to: 1, 2, 3 Can anyone please help me understand this command? Please use code tags when... (1 Reply)
Discussion started by: mohan44
1 Replies

2. Shell Programming and Scripting

Help to understand the command

Hi Gurus, I am new for Unix scripting. below command in one existing script. I am not able to fully understand. please help in below command, I am not able to understand what's {P=1} do thanks in advance awk 'NF==1{$3=$1;$1=L}P&&NF>=3{print $1,$3;L=$1}/^___/{P=1}' FILE (3 Replies)
Discussion started by: green_k
3 Replies

3. Shell Programming and Scripting

understand sed

cat teledir.txt jai sharma 25853670 chanchal singhvi 9831545629 anil aggarwal 9830263298 shyam saksena 23217847 lalit chowdury 26688726 If i use the below command , it is giving me the output with "," in between two name. how ? and also i would like to know the reason for the space used in... (1 Reply)
Discussion started by: Antony Ankrose
1 Replies

4. Shell Programming and Scripting

I am learning regular expression in sed,Please help me understand the use curly bracket in sed,

I am learning SED and just following the shell scripting book, i have trouble understanding the grep and sed statement, Question : 1 __________ /opt/oracle/work/antony>cat teledir.txt jai sharma 25853670 chanchal singhvi 9831545629 anil aggarwal 9830263298 shyam saksena 23217847 lalit... (7 Replies)
Discussion started by: Antony Ankrose
7 Replies

5. Shell Programming and Scripting

Not able to understand use exec command

Hi i am in learning phase of unix. i was going through exec in a unix book. below is the command exec n>file exec n>>file however when i used the exec command like below , where ex is the file name exec 2>>exand then do ls -lrt then again when i do the ls -lrt to see the size of the file... (3 Replies)
Discussion started by: scriptor
3 Replies

6. UNIX for Dummies Questions & Answers

Not able to understand the output of w command

I have taken putty session of a server from two separate machines namely HOST1(3 sessions) and HOST2(1 Session) . However w command says there are 5 users Confused over the output any clue will be appreciated. # w 09:29:36 up 34 days, 15:48, 5 users, load average: 0.62, 4.33, 8.16 USER ... (3 Replies)
Discussion started by: pinga123
3 Replies

7. Shell Programming and Scripting

I can't understand sed error output.

Hey forum, I have a problem with a script what used to work, but suddenly is not working anymore. I have been trying different things for an hour now and I give up :D . #!/bin/sh asukoht=`pwd` template=$1 for values in... (4 Replies)
Discussion started by: mario8eren
4 Replies

8. Shell Programming and Scripting

trying to understand what sed is doing?

Can someone help me understand why sed '/host/ s/$/QQQ/g' junk is taking the file 'junk' which is this: host Example_1 filename-"gfnwd.cfg"; hardware-ethernet-00:13:11:fd:7a:88; fixed-address-10.10.6.19; } host Example_2 filename-"gfnwd_280.cfg";... (2 Replies)
Discussion started by: TheBigAmbulance
2 Replies

9. HP-UX

Need help to understand chatr command

Hi, I am trying to find the max memory utilization of a binary file using chatr command. i gave chatr <file name>. But no where i could see the max memory usage of the file. How do you i check the memory usage of this binary file. Upto my knowledge it should be 1.75GB in HP-UX. But the does... (1 Reply)
Discussion started by: kprasanna_79
1 Replies

10. UNIX for Dummies Questions & Answers

Can't understand sar command

HI Experts, Can anyone pls help me to understand this.. >sar 20:05:00 1 2 1 96 20:10:00 2 2 10 87 20:15:00 1 2 19 78 20:20:00 1 2 14 83 20:25:00 1 2 16 81 20:30:00 1 ... (1 Reply)
Discussion started by: shaan_dmp
1 Replies
Login or Register to Ask a Question