Simple SED edit


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple SED edit
# 1  
Old 01-16-2007
Simple SED edit

I have output like the following:

B D 20070116095820001 N D S0000579.LOG S0000582.LOG
B D 20070116095750001 N D S0000574.LOG S0000576.LOG
B D 20070116095734001 N D S0000570.LOG S0000573.LOG
B D 20070116095705001 N D S0000569.LOG S0000569.LOG
B D 20070116095644001 N D S0000566.LOG S0000567.LOG
B D 20070116095556001 N D S0000563.LOG S0000566.LOG
B D 20070116095516001 N D S0000562.LOG S0000562.LOG
B D 20070116095313001 N D S0000562.LOG
B D 20070116094213001 N D S0000562.LOG
B D 20070116094018001 N D S0000559.LOG
B D 20070116093927001 N D S0000553.LOG S0000553.LOG
B D 20061219112717001 F D S0000000.LOG S0000000.LOG

and I need to grab the 5th occurance of *.LOG (S0000570.LOG). The catch is that the number preceeding the .LOG string will change and the entire line is actually one word (verified this by trying to search for just the word S0000570.LOG using grep -w S0000570.LOG and I got the entire line back). The consistant thing is that the *.LOG string i need will always be 11 characters (such as S0000570.LOG). Can I do this with SED?

*edit* grammer
# 2  
Old 01-16-2007
I found this browsing around that will somewhat do:

sed "s/.*\(S[0-9][0-9][0-9][0-9][0-9][0-9][0-9].LOG\).*/\1/" file

what it gives me is a list that looks like this:

S0000582.LOG
S0000576.LOG
S0000573.LOG
S0000569.LOG
S0000567.LOG
S0000566.LOG
S0000562.LOG
S0000562.LOG
S0000562.LOG
S0000559.LOG
S0000553.LOG
S0000000.LOG

While thats not exactly what I want, I believe I can pull out the 4th line, which will tell me what I need. Any one know of a better way to do this?
# 3  
Old 01-16-2007
Quote:
Originally Posted by rdudejr
I have output like the following:

B D 20070116095820001 N D S0000579.LOG S0000582.LOG
B D 20070116095750001 N D S0000574.LOG S0000576.LOG
B D 20070116095734001 N D S0000570.LOG S0000573.LOG
B D 20070116095705001 N D S0000569.LOG S0000569.LOG
B D 20070116095644001 N D S0000566.LOG S0000567.LOG
B D 20070116095556001 N D S0000563.LOG S0000566.LOG
B D 20070116095516001 N D S0000562.LOG S0000562.LOG
B D 20070116095313001 N D S0000562.LOG
B D 20070116094213001 N D S0000562.LOG
B D 20070116094018001 N D S0000559.LOG
B D 20070116093927001 N D S0000553.LOG S0000553.LOG
B D 20061219112717001 F D S0000000.LOG S0000000.LOG

and I need to grab the 5th occurance of *.LOG (S0000570.LOG). The catch is that the number preceeding the .LOG string will change and the entire line is actually one word (verified this by trying to search for just the word S0000570.LOG using grep -w S0000570.LOG and I got the entire line back). The consistant thing is that the *.LOG string i need will always be 11 characters (such as S0000570.LOG). Can I do this with SED?

*edit* grammer
An awk solution:

awk 'NR==5{print $NF RS}' RS=".LOG" infile


Regards
Dimitre
# 4  
Old 01-16-2007
Can you explain to me what that is doing? I would like to know more about awk and sed.
# 5  
Old 01-16-2007
Quote:
Originally Posted by rdudejr
Can you explain to me what that is doing?
Sure:
- change the default input record separator (RS) to ".LOG",
so the records become:

B D 20070116095820001 N D S0000579
S0000582

B D 20070116095750001 N D S0000574
...

- match record number 5 (NR==5,
NR is the total number of input records seen so far)
and print the last field (NF is the number of fields in the current input record,
so $NF is the last field) and the record separator (RS) itself.

Quote:
I would like to know more about awk and sed.
You have Internet Smilie


Regards
Dimitre
# 6  
Old 01-16-2007
Wow amazing! Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using sed to edit multiple files

Created a shell script to invoke sed to edit multiple files, but am missing something. Here's the shell script: oracle:$ cat edit_scripts.sh #!/bin/sh #------------------------------------------------------------------------------ # edit_scripts.sh # # This script executes sed to make global... (4 Replies)
Discussion started by: edstevens
4 Replies

2. Shell Programming and Scripting

edit sed command

how can i make this sed command run faster? sed '51000000,51347442!d' file and sed '51347442,$ !d' file File is a 9GB in size. it runs on sunos 5.10 and linux red hat 6 servers and i use bash. (5 Replies)
Discussion started by: SkySmart
5 Replies

3. Shell Programming and Scripting

Script to make simple recurring ascii file edit

Hi, I have an ascii file with recurring lines (the file is 36mb so lots of lines) which look like this: -2.5 -66.324-68.138 935.2 1.953 -0.664 272.617 73.684 -2.428 269.998 0.000 Every 14 lines there is a blank line. I would like to, for each non-blank line,... (2 Replies)
Discussion started by: blueade7
2 Replies

4. Shell Programming and Scripting

edit field using sed or awk

please help me to edit the second field using awk or sed i have input file below aa1001 000001 bb1002 000002 cc1003 000003 so i want the output file like below aa1001 01 bb1002 02 cc1003 03 (38 Replies)
Discussion started by: zulabc
38 Replies

5. UNIX for Dummies Questions & Answers

sed to edit nth filed

Hi all, I want to edit nth filed of a comma delimited line with some value. Can I use sed command to do this. Pls suggest me the command here. Thanks, Poova. (2 Replies)
Discussion started by: poova
2 Replies

6. Shell Programming and Scripting

sed edit in place -i issues

Hello, I am attempting to create a command that I can eventually put into a loop so I can edit 1file on many servers. I would like to edit the file in place with sed -i. If not I will take any suggestions on how to use a temp file. I need to remove a email address from the configuration file... (4 Replies)
Discussion started by: abacus
4 Replies

7. Shell Programming and Scripting

Sed or Awk or both to edit file

What is an efficient way to remove all lines from the input file which contain a file name? inputfile: ======================= # comment # comment # comment 5 8 10 /tmp 5 8 10 /var/run 5 8 10 /etc/vfstab 5 8 9 /var/tmp 5 8 10 /var/adm/messages... (7 Replies)
Discussion started by: Arsenalman
7 Replies

8. Shell Programming and Scripting

Help edit simple payroll script?

I'm trying to write a simple script to figure pay with overtime...I got the first part to work, but I can't seem to get the second if statement's syntax right...:confused:I want it to take the 40 hours times 10 dollars, but then i want whatever is left over (like 7 of 47 hours) and take that times... (6 Replies)
Discussion started by: miss72006
6 Replies

9. Shell Programming and Scripting

SED text edit help needed

Could someone please tell me how to delete all lines above a line which contains a particular string? (possibly using SED command) I know how to do this if the target string appears in only one line of file but when it appears in multiple lines it only deletes from the first line which the string... (3 Replies)
Discussion started by: stevefox
3 Replies

10. UNIX for Dummies Questions & Answers

simple file edit

What command can I use to simply edit a file by searching for a word and then deleting the lines that I find that word in? (4 Replies)
Discussion started by: capesong
4 Replies
Login or Register to Ask a Question