Nested sed commands


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Nested sed commands
# 8  
Old 01-02-2015
Quote:
Originally Posted by Nic2015
...
that the final result looks like
Code:
3 200

or better only the index 3. But the call have to be robust that I never would get Choice 13 with 2000.
I gave you a solution to this.
Even for just the value, show some adaption effort.
Or describe what you really want and share what you've done.

Thank you.
# 9  
Old 01-02-2015
If I understand what you're trying to do, this seems to work:
Code:
gphoto2 --get-config /main/imgsettings/iso | awk ' 
/^Current/ { speed = $2; next }
speed && $3 == speed { print $2; exit }'

If you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk.
# 10  
Old 01-02-2015
Super-safe (speed=0, leading space, ...)
Code:
gphoto2 --get-config /main/imgsettings/iso | awk '
$1=="Current:" { speed=$2; f=1 }
f==1 && $1=="Choice:" && $3==speed { print $2; exit }'

# 11  
Old 01-03-2015
Thank y all for y support.
There is another solution but only with sed:
Code:
ghoto2 --get-config /main/imgsettings/iso | sed -n "/Current: /h;G;s/Choice: \([0-9]\+\) \(.*\)\nCurrent: \2/\1/p"

# 12  
Old 01-05-2015
I think that a 200 would match a 2000. An attempt to make it more robust:
Code:

ghoto2 --get-config /main/imgsettings/iso |
sed -n '
/^ *Current:/{
s/.*: *//
h
}
G
s/^ *Choice: *\([^ ]*\)  *\([^ ]*\) *\n\2 *$/\1/p'

But awk is a better choice here because of its splitting on white-space.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Sed, matching nested brackets and deleting

1. The problem statement, all variables and given/known data: I have to write a script using sed, which delete everything between curly brackets and the brackets themself. The brackets might be nested. The input-file is: aaa { bbb ccc { ddd eee } fff { ... (2 Replies)
Discussion started by: FuzzyGnome
2 Replies

2. Shell Programming and Scripting

Complex bash/sed, variables and nested quotes

Ok, this one isn't for everybody, it's pretty tough and I've spent a good deal of time on it without figuring it out yet. Can anybody get this script to work: #!/bin/bash cq_fname="%let outputfile="/user/cq_"$1".csv";" sed "29s/.*/\"$cq_fname\"/" file1.sas >... (3 Replies)
Discussion started by: nocloud
3 Replies

3. Shell Programming and Scripting

Grouping sed commands

Hello, would you please help me with why my SED command file is outputting the entire input file instead of only the text that I'm trying to block? cat testfile O 111111111-00 DUE-DATE METHOD: FREQUENCY: O 222222222-00 DUE-DATE METHOD: FREQUENCY: O 333333333-02 DUE-DATE METHOD:... (4 Replies)
Discussion started by: lneedh1
4 Replies

4. Shell Programming and Scripting

sed help - nested pattern

Hello, I am very new to Unix and using sed so I'm struggling a little bit with this command and was hoping someone could help me out. I want to find a nested pattern in a file and replace some text in that file with text from another file. For example, in file one I have something like... (11 Replies)
Discussion started by: planetary12
11 Replies

5. UNIX for Dummies Questions & Answers

Bourne-sh (not bash) question about nested loops and sed

Here's the input: alpha, numeric or alphanumeric string ("line 1 string") numeric string ("line 2 string") numeric string ("line 3 string") numeric string ("line 4 string") ... where - each numeric string is in a pattern that can be matched with RE but - there can be any number of... (2 Replies)
Discussion started by: uiop44
2 Replies

6. Shell Programming and Scripting

merging sed commands

Hi, I've a shell that uses two sed commands to tailor a file. sed 's/ */ /g' | sed 's/%/%%/g' Is it possible to merge this in to a single sed? Thanks! (2 Replies)
Discussion started by: dvah
2 Replies

7. Shell Programming and Scripting

Running sed commands

Hello I need to run some sed commands but it involves "/" in the substitute or delete, any ideas how I get round the problem. Example: cat file1.txt | sed -e '/</Header>/d' > file2.txt This errors due to the forward slash before the Header text. Thanks (3 Replies)
Discussion started by: Dolph
3 Replies

8. UNIX for Dummies Questions & Answers

combining sed commands

I would like to change the lines: originalline1 originalline2 to: originalline1new originalline1newline originalline2new originalline2newline To do this, id like to combine the commands: sed 's/^/&new/g' file > newfile1 and sed '/^/ a\\ newline\\ \\ (2 Replies)
Discussion started by: Dave724001
2 Replies

9. Shell Programming and Scripting

multiple sed commands

hello! I have a few sed commands sed '/^$/d' < $1 > tmp.t sed '/^ \{3,\}/d' < tmp.t > tmp1.txt ..... how can I write them in a single line? sed '/^$/d' < $1 > | '/^ \{3,\}/d' < $1 > tmp1.txt any idea? thanks. (5 Replies)
Discussion started by: george_
5 Replies

10. Shell Programming and Scripting

sed commands

I have a configuration file that when a certain script runs in updates. I want to use sed and can't seem to get the syntax right. A line from the configuration file looks like: DATE=20040909 12:00:10 When the script is run I want to change the date and time, i.e. removing the previous... (7 Replies)
Discussion started by: dbrundrett
7 Replies
Login or Register to Ask a Question