Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWK scripting :How to remove Field separator using awk

Tags:

shell

awk

Need the following output

ONGC044 
ONGC043
ONGC042
ONGC041
ONGC046
ONGC047

from this input

Medium Label                   Medium ID                            Free Blocks
===============================================================================
[ONGC044] ECCPRDDB_FS_43       ac100076:4aed9b39:44f0:0001            195311616
[ONGC043] ECCPRDDB_FS_42       ac100076:4aed9b1d:44e8:0001            195311616
[ONGC042] ECCPRDDB_FS_41       ac100076:4aed9af4:4469:0001            195311616
[ONGC041] ECCPRDDB_FS_40       ac100076:4aed9ad3:445e:0001            195311616
[ONGC046] ECCPRDDB_FS_44       ac100076:4aedd04a:68c6:0001            195311616
[ONGC047] ECCPRDDB_FS_45       ac100076:4aedd4a0:6bf5:0001            195311616
like image 972
user356393 Avatar asked Jul 12 '26 23:07

user356393


2 Answers

awk -F"[][]" 'NR>2{print $2}' file
like image 195
ghostdog74 Avatar answered Jul 14 '26 13:07

ghostdog74


I think what you want is:

awk '/^\[.*\]/  {print substr($1,2,7)}' < ~/tmp/awk_test/file

This assumes that your first field is exactly 9 (7 of them are the ones you want) characters each time. If this is not the case, then use the following instead to strip off of the [ and the ] from the first field:

awk '/^\[.*\]/  {gsub(/[\[\]]/,"",$1); print $1 }' < ~/tmp/awk_test/file
like image 42
whaley Avatar answered Jul 14 '26 15:07

whaley