Minsec
Minsec

Reputation: 35

Find a text within a pattern using awk in UNIX

I have many text files with the 1st line being in the following format in individual files.

/*tablename-Employee*/ 
/*tablename-Department*/
/*tablename-Orders*/

I would like to fetch Employee, Department and Orders from each individual file using awk.

I tried this, but didn't see any output.

 awk '/^[\/]*tablename: / {print $1}' employee_file.sql
 awk '/^[\/]*tablename: / {print $1}' department_file.sql
 awk '/^[\/]*tablename: / {print $1}' order_file.sql

Expected Output from individual command.

Employee
Department
Orders

Upvotes: 1

Views: 29

Answers (1)

anubhava
anubhava

Reputation: 784898

You can use awk:

awk -F '[-*]' 'NR == 1{print $3}' file1
Employee

awk -F '[-*]' 'NR == 1{print $3}' file2
Department

awk -F '[-*]' 'NR == 1{print $3}' file3
Orders

Upvotes: 1

Related Questions