Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash sed a quoted string from file but only at the Nth line

Tags:

bash

sed

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
like image 345
user3353499 Avatar asked Dec 20 '22 17:12

user3353499


1 Answers

Awk would be my preferred solution here.

awk -F'"' 'NR==2{print $2}'
like image 82
kojiro Avatar answered Feb 15 '23 19:02

kojiro