Hi
Can anyone help me to identify the nth field from a Tab delimited file?
Thanks
Subrat
Hi
Can anyone help me to identify the nth field from a Tab delimited file?
Thanks
Subrat
Using cut command you can identify a particular field for the specified delimiter.
General format:
cut -d"<delimter>" -f"<field_number>" filename
You need to specify the tab delimiter by the -d option.
But you can not hit tab key because shell will not accept tab key. Also you can not give '\t' as its argument.Because cut -d expects a single character as its argument.
To give tab stop in the shell you just hit ctrl+v and ctrl+i
cut -d ' ' -f 4 file # Here the tab given inside the single quotes by using ctrl+v and ctrl+i
Try awk:
awk '{ print $4 }' file
I tried all your suggestion.. but unfortunatly none of them worked .
Can you execute the below command and paste the output?
cat -vet file
This should work. What is the error ur getting please post it.
---------- Post updated at 03:04 PM ---------- Previous update was at 02:59 PM ----------
may be u try with
awk -F " " '{ print $4 }' file.
here " " is tabkey
OUTPUT:-
cat -vet file
5^I220730^I1587652^I^I^I^I1^IHCAT^I^I^ISTD^I^I101^I^I^I^I^I^I^I^I^I01/08/2007^I^IGBP^IG^I^I^I1^I^I793165^I^I^I^I^I^IUK^I^I10045^I25/09/2007^IUK^I^IKK^I^I^I^I^I^I^I^I^I^I900593^I^I^I^I^I^I31/08/2008^I^I^I^I^I^IUK^IA^I^I^I^IC^I^I10101^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^IY^I25^IN^I^IN^I^I^I^I^I^I^I^I^I^I^I^ISMA83^IN^I^I^I^I^I^I^I^I^I^IC^I^I^I^I^I^ISTD1^I01/08/2007^I^I^I^I^I^I^I^I^I^I^I^I^I^I^IN^I^I$
awk -F " " '{ print $4 }' file.
Its output coming as blank.
5^I220730^I1587652^I^I^I^I1^IHCAT^I^I^ISTD^I^I101^I^I^I^I^I^I^I^I^I01/08/2007^I^IGBP^IG^I^I^I1^I^I793165^I^I^I^I^I^IUK^I^I10045^I25/09/2007^IUK^I^IKK^I^I^I^I^I^I^I^I^I^I900593^I^I^I^I^I^I31/08/2008^I^I^I^I^I^IUK^IA^I^I^I^IC^I^I10101^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^I^IY^I25^IN^I^IN^I^I^I^I^I^I ^I^I^I^I^I^ISMA83^IN^I^I^I^I^I^I^I^I^I^IC^I^I^I^I^I^ISTD1^I01/08/2007^I^I^I^I^I^I^I^I^I^I^I^I^I^I^IN^I^I$
Yes it will show null as the 4th filed is null . See the marked tab's