Thursday, 4 August 2016

How To Fetch Specific Field In Multi Character Delimiter File Using AWK

In earlier articles we have seen awk command to fetch a specific field where we have single character delimiter. Here we will see how can we fetch specific field where data is separated by multi character delimiter.

$ echo "1001***A1***HR***5000" | awk -F'***' '{print $1}' 

Output:
awk: There is a regular expression error.
        ?, *, or + not preceded by valid regular expression


$ echo "1001***A1***HR***5000" | awk -F'[*][*][*]' '{print $1}' 
Output:
1001

You can achieve the same by cut command as given below:

$ echo "1001***A1***HR***5000" | cut -d'***' -f1

Output:
1001

Keep Reading, Keep Learning, Keep Sharing...!!
Related Posts Plugin for WordPress, Blogger...