BASH - storing index value from another file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting BASH - storing index value from another file
# 8  
Old 11-08-2011
whats the error you are getting while executing the awk?...

--ahamed
# 9  
Old 11-08-2011
The error I encountered were
Code:
awk: line 2 (Which is an empty line) syntax error at or near ]
awk: line 5 (Which is the first "{") syntax error at or near ,

And ahamed, for your "infile" is that a syntax or it's referring to the file to use.
Thank you!

Last edited by vinzping; 11-08-2011 at 01:56 AM.. Reason: adding question
# 10  
Old 11-08-2011
Try gawk instead of awk...
--ahamed
# 11  
Old 11-08-2011
Tried, error was "gawk: command not found"
# 12  
Old 11-08-2011
Quote:
Originally Posted by vinzping
The error I encountered were
Code:
awk: line 2 (Which is an empty line) syntax error at or near ]
awk: line 5 (Which is the first "{") syntax error at or near ,

And ahamed, for your "infile" is that a syntax or it's referring to the file to use.
Thank you!
infile is the file with the data... A1,A2 etc...

are you sure you are not missing anything while copying the code from here?...
Cause its working for me in Linux and Solaris!

--ahamed
# 13  
Old 11-08-2011
Quote:
Originally Posted by ahamed101
infile is the file with the data... A1,A2 etc...

are you sure you are not missing anything while copying the code from here?...
Cause its working for me in Linux and Solaris!

--ahamed
Quote:
I've changed the infile to the file I'm using but i still got the 2 lines of error.

Just to clarify, for the first line of code. Is that a Single Quote or a Back Tick?
Code:
awk -F, '

And in my flat file it actually contains more than 1 line of data. However I did tried compiling with 1 line of data in the flat file but to no avail.

I'm wondering could it be my Ubuntu doesn't supports awk?
---------- Post updated at 02:18 PM ---------- Previous update was at 02:11 PM ----------

I've copied and paste exactly what you have typed in your earlier post. And now I get only 1 error stating

Code:
awk: line 5: syntax error at or near ,

Line 5 is "{"

Is there any specified format I need to save my file?

Currently my file doesn't have any file extension, only filename "forumTest".

In it the codes are
Code:
#!/bin/bash
 
awk -F, ' 
BEGIN{ for(i=65;i<=71;i++) al[sprintf("%c",i)]=++j }
{
        for(i=1;i<=NF;i++){
                match($i,/([A-Z]*)([0-9]*)/,arr)
                a[arr[1]"-"arr[2]]=$i
        }
}
END{
        printf "\t"
        for(i in al) printf i"\t"
        for(i=1;i<=7;i++){
                printf "\n"i
                for(j in al) {
                        printf "\t"
                        printf a[j"-"i]?"X":""
                }
        }
        printf"\n"
}
' FlightSeat


Last edited by vinzping; 11-08-2011 at 02:19 AM.. Reason: grammer
# 14  
Old 11-08-2011
It is a single quote... mmm... something is missing somewhere... try this...
Code:
awk -F"," '{...}' infile

--ahamed
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Finding specific string in file and storing in another file

Text in input file is like this <title> <band height="21" isSplitAllowed="true" > <staticText> <reportElement x="1" y="1" width="313" height="20" key="staticText-1"/> <box></box> <textElement> <font fontName="Arial" pdfFontName="Helvetica-Bold"... (4 Replies)
Discussion started by: aankita30
4 Replies

2. Programming

Storing a Temporary File Using C

How would someone save a file such as /etc/vpnc/test.conf locally into a temp file, so it can be queried? So for example if I used rsync to copy this file locally, how would I add that to a temp_file variable and discard it using unlink? #include <stdio.h> #include "error.h" ... (15 Replies)
Discussion started by: metallica1973
15 Replies

3. Shell Programming and Scripting

file index operation in loop

i have one file which contains data like the below DE_CODE|AXXANY|APP_NAME|TELCO|LOC|NY DE_CODE|AXXATX|APP_NAME|TELCO|LOC|TX DE_CODE|AXXABT|APP_NAME|TELCO|LOC|BT DE_CODE|AXXANJ|APP_NAME|TELCO|LOC|NJ DE_CODE|AXXANJwt|APP_NAME|TELCO|LOC|WT am going use a for loop or whole loop which will... (3 Replies)
Discussion started by: mail2sant
3 Replies

4. Shell Programming and Scripting

Search an array and return index (bash)

Hi all, In bash, is there any way of searching an array and returning the index? For example, how could I write a script that would do the following: >> search note_array=(C D E F G A B) for F return the value 3 (or 4) Thanks, R (5 Replies)
Discussion started by: RMontenegro
5 Replies

5. Shell Programming and Scripting

Storing blanks in an array in bash

Hi Guys, I have a file which is as follows: 1 2 4 6 7 I am trying to store these values in an array in bash. I have the following script: FILE=try.txt ARRAY=(`awk '{print}' $FILE`) echo ${ARRAY} (3 Replies)
Discussion started by: npatwardhan
3 Replies

6. Shell Programming and Scripting

Removing the index file

Hi Folks, Under the path /home, I need to remove the index.html/php files from all the users. But the thing is I need to move the index file from the username starting with a-d, then e-g. How can I do this via the shell script. (2 Replies)
Discussion started by: gsiva
2 Replies

7. Shell Programming and Scripting

Sort from start index and end index in line

Hi All, I have a file (FileNames.txt) which contains the following data in it. $ cat FileNames.txt MYFILE17XXX208Sep191307.csv MYFILE19XXX208Sep192124.csv MYFILE20XXX208Sep192418.csv MYFILE22XXX208Sep193234.csv MYFILE21XXX208Sep193018.csv MYFILE24XXX208Sep194053.csv... (5 Replies)
Discussion started by: krish_indus
5 Replies

8. UNIX for Dummies Questions & Answers

wh inode index starts from 1 unlike array index (0)

brothers why inode index starts from 1 unlike array inex which starts from 0 its a question from the design of unix operating system of maurice j.bach i need to know the answer urgently...someone help please (1 Reply)
Discussion started by: sairamdevotee
1 Replies

9. Filesystems, Disks and Memory

why the inode index of file system starts from 1 unlike array index(0)

why do inode indices starts from 1 unlike array indexes which starts from 0 its a question from "the design of unix operating system" of maurice j bach id be glad if i get to know the answer quickly :) (0 Replies)
Discussion started by: sairamdevotee
0 Replies

10. Shell Programming and Scripting

how to delete record in file data with index in another file?

I want to deal with several data, i.e., data.*.txt with following structure MSG|20010102|123 125 4562 409|SEND MSG|20010102|120 230|SEND MSG|20010102|120 204 5071|SEND MSG|20010103|2 11 1098 9810|SEND ...... index file index.txt is 11 201 298 100 ...... What I want to do is: 1)... (0 Replies)
Discussion started by: zhynxn
0 Replies
Login or Register to Ask a Question