sed replacement command (2)

Keywords: Operation & Maintenance Database

The input file will not be modified, sed only executes the replacement command in the schema space, and then outputs the schema space's
Content.
Text file employee.txt

101,John Doe,CEO
102,Jason Smith,IT Manager
103,Raj Reddy,Sysadmin
104,Anand Ram,Developer
105,Jane Miller,Sales Manager

1. Replace Manager in all rows with Director
Replacement commands use parameters s to pay attention to the code format

[root@localhost /]# sed 's/Manager/Director/' employee.txt
101,John Doe,CEO
102,Jason Smith,IT Director
103,Raj Reddy,Sysadmin
104,Anand Ram,Developer
105,Jane Miller,Sales Director

2. Replace the Manager in the row containing Sales with Director only

[root@localhost /]# sed '/Sales/s/Manager/Director/' employee.txt
101,John Doe,CEO
102,Jason Smith,IT Manager
103,Raj Reddy,Sysadmin
104,Anand Ram,Developer
105,Jane Miller,Sales Director

3. Global Marker g
Replace the first lowercase letter a with capital A

[root@localhost /]# sed 's/a/A/' employee.txt
101,John Doe,CEO
102,JAson Smith,IT Manager
103,RAj Reddy,Sysadmin
104,AnAnd Ram,Developer
105,JAne Miller,Sales Manager

Replace all lowercase letters a with uppercase letters A

 [root@localhost /]# sed 's/a/A/g' employee.txt
101,John Doe,CEO
102,JAson Smith,IT MAnAger
103,RAj Reddy,SysAdmin
104,AnAnd RAm,Developer
105,JAne Miller,SAles MAnAger

4. Digital Signs
Replace the second lowercase letter a with the capital letter A

[root@localhost /]# sed 's/a/A/2' employee.txt
101,John Doe,CEO
102,Jason Smith,IT MAnager
103,Raj Reddy,SysAdmin
104,Anand RAm,Developer
105,Jane Miller,SAles Manager

Create a document

vi substitute-locate.txt
locate command is used to locate files
locate command uses database to locate files
locate command can also use regex for searching

Replace the location that appears the second time in each line with find using the file you just created

[root@localhost /]# sed 's/locate/find/2' substitute-locate.txt
locate command is used to find files
locate command uses database to find files
locate command can also use regex for searching

5. Print logo p
Replace the second location in each line with find and print it out

Insert code slices here

Posted by kingbeastie on Wed, 30 Jan 2019 02:27:15 -0800