raju Patil raju Patil - 1 month ago 6
Bash Question

How to print only first word after the equal sign

enter image description here

Input file(present in

/sys/test/list.txt
):

"BA_FN" = "John" <<NEW>>

"BA_ACCOUNT_NO" = "AACtesting56" <<NEW>>

"BA_BILLINFO_ID" = "BULCA8-67" <<NEW>>

"BA_LN" = "winslet" <<NEW>>


I need to print only below values using shell script:

John

AACtesting56

BULCA8-67

winslet


Can someone help me pls?

Answer

Say the content is in file sample.txt and it looks like

"BA_FN" = "John"    <<NEW>>

"BA_ACCOUNT_NO" = "AACtesting56"    <<NEW>>

"BA_BILLINFO_ID" = "BULCA8-67"    <<NEW>>

"BA_LN" = "winslet"    <<NEW>>

we can print with below command

cat sample.txt |awk -F"=" '{split($2,a," ");gsub(/"/, "", a[1]);print a[1]}'

output will be

John

AACtesting56

BULCA8-67

winslet
Comments