LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-28-2017, 07:06 AM   #1
sysmicuser
Member
 
Registered: Mar 2010
Posts: 437

Rep: Reputation: 0
Need some help regex please


Hi Guys,

I am have a yaml file and it has the following text:

Code:
  /data/app0:
     server: x.y.z.p
     share: /data/app0
     mount: /data/app/0
And I want to have the following output:

Code:
  /data/app0:
     server: x.y.z.p
     share: /data/app0
     mount: /data/app/0
     options: _netdev,noatime,nodiratime
I tried the following which is a simple regex expression used -i and a but it is throwing an error:

Code:
[user@jump nodes]$ cat test.yaml
  /data/app0:
     server: x.y.z.p
     share: /data/app0
     mount: /data/apps/0
  /data/app1:
     server: x.y.z.p
     share: /data/app1
     mount: /data/apps/1
  /data/app2:
     server: x.y.z.p
     share: /data/app2
     mount: /data/apps/2
  /data/app3:
     server: x.y.z.p
     share: /data/app3
     mount: /data/apps/3

[user@jump nodes]$ sed -i '/mount: /data/app/*/a \
options: _netdev,noatime,nodiratime \' test.yaml
sed: -e expression #1, char 11: extra characters after command
[user@jump nodes]$
No idea why it is going wrong ?
 
Old 05-28-2017, 08:03 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,821

Rep: Reputation: 3084Reputation: 3084Reputation: 3084Reputation: 3084Reputation: 3084Reputation: 3084Reputation: 3084Reputation: 3084Reputation: 3084Reputation: 3084Reputation: 3084
sed will see all of the / as arguments so more than 2 without the use of 's', as in s///, and it is incorrect . You will need to escape all the ones that are part of the regex.

Also, do not confuse globbing with regex. /data/app/*/ -- this is looking for zero or more / after the string 'app' followed by a single / (also it is probably meant to be 'apps'.
Try using a digit qualifier, [0-9]
 
Old 05-28-2017, 08:07 AM   #3
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 20 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918Reputation: 2918
I'm not an expert on sed but:

i) The second forward slash (before data) will be interpreted as the end of the sed clause. You need to escape all literal forward slashes.

ii) What is that second backslash (\) character doing there? It will escape the final single quote.

iii) You're looking for /data/app/... but the data in your data file contains /data/apps/...

Edit: Oops, beaten to it...

Last edited by hydrurga; 05-28-2017 at 08:08 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to convert nginx regex to apache regex centosfan Linux - Server 1 12-08-2016 05:22 AM
Confusing issue with Perl regEx - Regex check seems to require variable being set EnderX Programming 1 09-07-2013 04:36 AM
[SOLVED] differences between shell regex and php regex and perl regex and javascript and mysql golden_boy615 Linux - General 2 04-19-2011 01:10 AM
Perl to find regex and print following 5 lines after regex casperdaghost Linux - Newbie 3 08-29-2010 08:08 PM
regex with sed to process file, need help on regex dwynter Linux - Newbie 5 08-31-2007 05:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration