Sed/UNIX help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sed/UNIX help
# 1  
Old 04-15-2014
Sed/UNIX help

Can someone explain what this sed statement mean to me?

Code:
zcat 2014-04-09.txt.gz | grep -a 'CodeOne:.*CodeTwo=101' | grep -v 'List=Pass' | sed 's/^.*Pass=\([0-9]*\),.*Reject=\([0-9]*\),.*All=\([a-zA-Z]*\),.*$/\1,\2,\3/'


I think what confusing mean is the .* and the *$. Now exactly sure how they work.
# 2  
Old 04-15-2014
Change any input line that matches:
Code:
arbitraryPASS=digits,arbitraryReject=digits,arbitraryAll=letters,arbitrary

to a line of the form:
Code:
digits,digits,letters


Last edited by Don Cragun; 04-15-2014 at 02:46 PM.. Reason: Fix typo.
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 04-15-2014
.* in the sed RE means any number of characters (including 0 characters).
The ^.* at the beginning and the .*$ at the end of your RE do not do anything but waste a few (or many, dependent on the sed implementation) CPU cycles.
Well, the ^.*, because it is a maximum (greedy) match, shifts the remainder to the rightmost match.
# 4  
Old 04-15-2014
Quote:
Originally Posted by Don Cragun
Change any input line that matches:
Code:
arbitraryPASS=digits,arbitraryReject=digits,arbitraryAll=letters,arbitrary

to a line of the form:
Code:
digits,digits,letters

Thanks. That's quite helpful. Explain /\1,\2,\3/. It apear this mean string 1,2 and 3?

So basically whats's going is sed substitute arbitraryPASS=digits,arbitraryReject=digits,arbitraryAll=letters,arbitrary with digits,digits, letters?
# 5  
Old 04-15-2014
\1 in the replacement string in the sed substitute command is replaced by the set of characters matched by expression in the 1st \(expression\) in the basic regular expression used in the sed substitution command's search pattern, \2 is replaced by the set of characters matched by the 2nd \(expression\), and \3 is replaced by the set of characters matched by the 3rd \(expression\).
This User Gave Thanks to Don Cragun For This Post:
# 6  
Old 04-15-2014
Quote:
Originally Posted by Don Cragun
\1 in the replacement string in the sed substitute command is replaced by the set of characters matched by expression in the 1st \(expression\) in the basic regular expression used in the sed substitution command's search pattern, \2 is replaced by the set of characters matched by the 2nd \(expression\), and \3 is replaced by the set of characters matched by the 3rd \(expression\).
Thanks. That make sense. Question. Would Pass, Reject and All be part of that expression? Or is it just looking for the values of Pass, Reject and All like ([0-9]*\ and ([0-9]*\ and a-zA-Z]*\?
# 7  
Old 04-15-2014
In the basic regular expression specifying the search pattern in the sed substitute command:
Code:
s/^.*Pass=\([0-9]*\),.*Reject=\([0-9]*\),.*All=\([a-zA-Z]*\),.*$/\1,\2,\3/

are Pass=, Reject=, and All= matched by any of the expressions shown in red text between \( and \) pairs? No!

The BRE: abc\(123\)def will match any string that contains the characters abc123def contiguously and in that order. If that BRE is used to match a string in a sed substitute command, \1 in the replacement string will be replaced by the characters that matched the subexpression between the subexpression delimiters \( and \) (in this case the substring 123).
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Working with if and sed in UNIX

I have a text file containing multiple lines like password="&test."; password="xyz"; password='write some'; password="&testwrite."; today='o1jan2017'd; ----------------- ------------------ I don't want to replace the string value which are starting with & for Password variable... (3 Replies)
Discussion started by: harshabag
3 Replies

2. Shell Programming and Scripting

Help me in awk or sed in UNIX

I have a fixed length file a.txt that looks like a@ a00 a00000 a00 a000000 a00 a0000 a0000 a00000000 a01 a@ a1 a2 a11 a22 a12 a13 a44 a45 a54 a65 a76 a77 a@ a1 a3 a6 a7 a9 a8 a2 a7 a8 a8 a9 a0 b@ b00... (7 Replies)
Discussion started by: RJG
7 Replies

3. How to Post in the The UNIX and Linux Forums

Help me in awk or sed in UNIX

I have a fixed length file that looks like a@ a00 a00000 a00 a000000 a00 a0000 a0000 a00000000 a01 a@ a1 a2 a11 a22 a12 a13 a44 a45 a54 a65 a76 a77 a@ a1 a3 a6 a7 a9 a8 a2 a7 a8 a8 a9 a0 b@ b00 b00000 b00... (1 Reply)
Discussion started by: RJG
1 Replies

4. UNIX for Advanced & Expert Users

UNIX sed command help

Hi, I am a new student learning about Unix. Can anyone help with the following sed command. What would this command do? sed -n -e '/^s/p' Any help you can provide would be a big help. Thanks in advance! (2 Replies)
Discussion started by: dgigga
2 Replies

5. UNIX for Dummies Questions & Answers

Using sed in unix

Please help on the usage of sed in unix. The questions are below : 1. how to display a particular word in a file using sed 2. how to replace a single letter in a word using sed ex : in a file, all the 'ram' should be replaced by 'Ram' 3. i want to display a particular word from file... (1 Reply)
Discussion started by: nani_ynm
1 Replies

6. Shell Programming and Scripting

sed -i not working in HP unix

hi i want to append the number in each file,but when i ran this command:- sed -i "1i 50" filename its giving error sed: illegal option -- i in HP unix but its working in linux. any advice !!!!!!!!! (6 Replies)
Discussion started by: abhigrkist
6 Replies

7. Shell Programming and Scripting

sed or unix question

hello, i have a csh file that calls a program and stores the output in a variable. the output is: \*\%VFT\$1\\3 as you can see there is a backslash before every non alphanumeric character. i save this output and then use SED to replace a word in a file with the output that i got. ... (3 Replies)
Discussion started by: davea402
3 Replies

8. UNIX for Advanced & Expert Users

unix awk/sed program

i need a sample unix awk/sed program to replace param3 in a file. i have sample file a.dat with the following format/length (week 8, sku 20, store 20 and qty 8). all store id's which end with _2 needs to be replaced with div id 2. all store id's which end with _1 needs to be replaced with div id... (4 Replies)
Discussion started by: mnnarendra
4 Replies

9. Shell Programming and Scripting

UNIX in the MacIntosh (for sed people)

Hi, I'm trying to use sed to process some files on Macs running OSX. Anyone know anything about Macs and sed? Here's the problem sed 's/^/ /g' test_file > endfile (there are spaces betwen the second and third /, but the forum software compresses them) This should put spaces at... (3 Replies)
Discussion started by: Laurel Maury
3 Replies

10. Shell Programming and Scripting

using sed in unix

I have a log file with over 500000 lines and I want to use sed command to filter through the file and delete the first 5000 lines. I have tried sed -e '1,5000d' fileA. where d is delete but this does not work. Any ideas ? Regards dodo14 :o (1 Reply)
Discussion started by: dodo14
1 Replies
Login or Register to Ask a Question