user3158126
user3158126

Reputation: 11

Printing a special column in a file using awk

I have a problem in printing a column that has names starting with ` (tick).

Below is the content in my file.

abc xyz pqr sym = `WST"    
abc xyz pqr sym = `WTFC"
abc xyz pqr sym = `WTI"
abc xyz pqr sym = `WTM"
abc xyz pqr sym = `WTR"

I want to print anything after the third column and I'm using the below code:

awk '{{printf "\n"} for(j=4;j<NF;++j){printf " %s",$j}}'

But,I'm not getting the expected output. Its not printing the last column. Could be because of tick character before the name. How can I make it to print the last column as well?

OUTPUT:

sym =
sym =
sym =    
sym =
sym =

EXPECTED OUTPUT:

sym = `WST"
sym = `WTFC"
sym = `WTI"
sym = `WTM"
sym = `WTR"

Upvotes: 1

Views: 48

Answers (1)

glenn jackman
glenn jackman

Reputation: 247210

It's because you're using j < NF instead of j <= NF

Since the field separator seems to be a single space, you could

cut -d " "  -f 4- file

Upvotes: 2

Related Questions