Reputation: 137
i know those two questions have been covered many time but i can't figure how to mix the two command in one:
get string between quote
sed 's/[^"]*"\([^"]*\)".*/\1/' "$file"
get line 2 from file
sed '2q;d' "$file"
many thanks for help.
EDIT:
input files are as follow:
#!/bin/bash
# "/path/to/folder/with/file.ext"
some others lines with quoted string
output
/path/to/folder/with/file.ext
Upvotes: 4
Views: 82
Reputation: 784958
You can combine 2 sed command using this sed:
sed '2s/[^"]*"\([^"]*\)".*/\1/p;d;q' file
/path/to/folder/with/file.ext
Upvotes: 4
Reputation: 123458
You could combine the two commands by saying:
sed -n '2s/[^"]*"\([^"]*\)".*/\1/p' filename
-n
would suppress automatic printing of pattern space2
before s
causes the substitution to be performed on line 2p
prints the current pattern spaceFor your input, it'd produce:
/path/to/folder/with/file.ext
Upvotes: 3
Reputation: 77059
Awk would be my preferred solution here.
awk -F'"' 'NR==2{print $2}'
Upvotes: 4