!!EMERGENCY!! - GREP/CUT to array

hi people,

I have a text file containing data, seperated by TAB. I want to process this tab'ed data as variable. how can I assign this?

Ex:

11aaa 12000 13aaa 14aaa 15aaa 16aaa 17aaa 
21aaa 22000 23aaa 24aaa 25aaa 26aaa 27aaa
31aaa 32000 33aaa 34aaa 35aaa 36aaa 37aaa
41aaa 42000 43aaa 44aaa 45aaa 46aaa 47aaa
51aaa 52000 53aaa 54aaa 55aaa 56aaa 57aaa
61aaa 62000 63aaa 64aaa 65aaa 66aaa 67aaa
71aaa 72000 73aaa 74aaa 75aaa 76aaa 77aaa

I want to fetch, lets say, "54aaa" (5th row, 4th col) as a variable to be able to process it. then I will call it as $qweasd=nameofthisvaribale. I have tried with grep and cut but no result as I want.

thanks for your assist.

Try:

awk 'NR==5{print $4}' infile

You can assign it to variable qweasd like this:

qweasd=$(awk 'NR==5{print $4}' infile)
1 Like

Everyone at the UNIX and Linux Forums gives their best effort to reply to all questions in a timely manner. For this reason, posting questions with subjects like "Urgent!" or "Emergency" and demanding a fast reply are not permitted in the regular forums.

For members who want a higher visibility to their questions, we suggest you post in the Emergency UNIX and Linux Support Forum. This forum is given a higher priority than our regular forums.

Posting a new question in the Emergency UNIX and Linux Support Forum requires forum Bits. We monitor this forum to help people with emergencies, but we do not not guarantee response time or best answers. However, we will treat your post with a higher priority and give our best efforts to help you.

If you have posted a question in the regular forum with a subject "Urgent" "Emergency" or similar idea, we will, more-than-likely, close your thread and post this reply, redirecting you to the proper forum.

Of course, you can always post a descriptive subject text, remove words like "Urgent" etc. (from your subject and post) and post in the regular forums at any time.

Thank you.

The UNIX and Linux Forums

absolutely excellent Scrutinizer thank you very much. this is absolutely what I want!!

thanks for your reply & timing :))

---------- Post updated at 11:34 AM ---------- Previous update was at 11:26 AM ----------

---------- Post updated at 11:37 AM ---------- Previous update was at 11:34 AM ----------

but I wonder, what about if my data is seperated by SPACE, or DOT, or COMMA? which parameter in this code specifies the TAB filter? can you give example for, lets say, SPACE?

By default awk separates using space characters so it will handle to TABs as well as space. To make it e.g. use TABs only you can use:

awk -F "\t" 'NR==5{print $4}' infile

likewise for . or ,

awk -F. 'NR==5{print $4}' infile
awk -F, 'NR==5{print $4}' infile

To use any number of space characters only (and not TABs):

awk -F" *" NR==5{print $4}' infile
1 Like

thank you very much Sucritinizer. that's all I want. :slight_smile: