-4

my file name is data.txt

employer_name salary designation

kundan 20000 accounts amit 15000 fielder chandan 25000 assi-hr .... .... .....

in this way i had created a file. i was looking for by using awk can i print employer name , salary and desigination in one line when i want to search a particular employeer data..

does awk reads excel files?

Community
  • 1
  • 1
aditya
  • 1
  • 1
  • 1
    What do you mean by *"Excel files"*? If your file is a text file (which I assume it is because you have called it `data.txt`) it is not an Excel file. Excel files normally end in `.xls` or `.xlsx` – Mark Setchell Aug 06 '16 at 12:56
  • wrt `does awk reads excel files?` - see [how-do-i-use-awk-under-cygwin-to-print-fields-from-an-excel-spreadsheet](http://stackoverflow.com/questions/38805123/how-do-i-use-awk-under-cygwin-to-print-fields-from-an-excel-spreadsheet) – Ed Morton Aug 06 '16 at 16:22

1 Answers1

0

If your data file really is space separated sequence of data, something like this would work:

$ cat >> find.awk
BEGIN {
    RS=" "
} 
NR%3==1 {
    name=$1
} 
name==find { 
    printf "%s%s", $1, (NR%3 ? OFS : ORS)
}

Test it:

$ awk -f find.awk -v find="kundan" data.txt
kundan 20000 accounts

If your data were:

kundan
20000
accounts
...

just remove the BEGIN block. If your data were:

kundan 20000 accounts
amit 15000 fielder
...

use grep ^kundan data.txt or awk -v find="kundan" '$1==find' data.txt but the latter is longer to write.

AWK does not read Excel files per se. You can export your Excel files to CSV files and run AWK against them. AWK likes CSV files. :D

James Brown
  • 36,089
  • 7
  • 43
  • 59
  • thank you for your help. but while run the above command [root@paramount Desktop]#awk -f find.awk -v find="kundan" data.txt kundan (#output while i was expecting entire that row to be print) currently i was doing [root@paramount Desktop]#vi search echo " enter the employer name :" read input grep -w "$input" data.txt [root@paramount Desktop]#./search kundan 20000 accounts – aditya Aug 06 '16 at 12:34