Awk: how to copy a range of rows in GAMS environment


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Awk: how to copy a range of rows in GAMS environment
# 1  
Old 05-03-2013
Awk: how to copy a range of rows in GAMS environment

Hi

I have a problem in using awk in GAMS. I have to copy a part of a .txt file selecting the rows between these two lines

Code:
"0 / END OF TRANSFORMER DATA, BEGIN AREA DATA"

"0 / END OF AREA DATA, BEGIN TWO-TERMINAL DC DATA"

I thought of using a command like this:



Code:
$onecho > area.awk
{  '/END OF TRANSFORMER DATA, BEGIN AREA DATA/, /END OF AREA DATA, BEGIN TWO-TERMINAL DC DATA/' print;
}
$offecho
$call awk -f area.awk support_file.txt > area.txt

but GAMS does not provide me the result I expect. The output file area.txt is empty.
When running the program, GAMS says also this line

Code:
awk: area.awk:1:   ^ invalid char  '''  in expression

Any idea is really appreciated Smilie

Last edited by radoulov; 05-03-2013 at 09:14 AM..
# 2  
Old 05-03-2013
Do you want data between those 2 lines including those lines or excluding them?

---------- Post updated at 05:35 PM ---------- Previous update was at 05:33 PM ----------

Your awk script should be

Code:
 
awk '/END OF TRANSFORMER DATA, BEGIN AREA DATA/,/END OF AREA DATA, BEGIN TWO-TERMINAL DC DATA/{print}' filename

You have entered ' after { which is causing error
# 3  
Old 05-03-2013
Thanks vidyadhar85 for your help. Anyways the situation has not changed. The output file is still empty! It's 4 hours I'm thinking about this things and it's driving me crazy!
# 4  
Old 05-03-2013
Quote:
Originally Posted by Pintug
Thanks vidyadhar85 for your help. Anyways the situation has not changed. The output file is still empty! It's 4 hours I'm thinking about this things and it's driving me crazy!
Then its time to provide the full details of your input file Smilie

try to put it between code tags
# 5  
Old 05-03-2013
The input file is a record of data.

So between expression like these

Code:
"0 / END OF TRANSFORMER DATA, BEGIN AREA DATA"

"0 / END OF AREA DATA, BEGIN TWO-TERMINAL DC DATA"

there s a list of data in the form like this

Code:
1041,'LD',1,   3,   1,     1.538,     0.507,     0.000,     0.000,     0.000,     0.000,   2
  1101,'I ',1,   5,   2,    10.999,     3.840,     0.000,     0.000,     0.000,     0.000,   5

I have to manipulate these data in GAMS
Therefore, I want to import the input file in GAMS.
I thought of dividing the input file in smaller files, one for each part of the recorded data; then, create my sets and parameters by importing the desired column with awk.
Then I will have to delete the stupid commas because I only need the numbers..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Concatenate rows and redefine range

I'm trying to find a way to concatenate consecutive rows (key is column $1 and $2) if column $5 an $6 are integers and redefine ranges in columns $3&$4 and $5&$6 Unfortunately I'm still learning the very basics so I cannot figure a way of doing this with awk. Input file 15 30 21 21 25.0... (11 Replies)
Discussion started by: alex2005
11 Replies

2. Shell Programming and Scripting

(hard one) awk, copy matching 2 col & 10-12 rows, is it possible?

Hey guys, my first post here. I'm trying to use awk to copy all matching paragraphs from one file The file looks like this : Test Case Number 990990003099 Card Type CCCC Transaction Type Sale Entry Mode Keyed Account Number 4099562299219923 Transaction Amount 78.88 Description lorem... (2 Replies)
Discussion started by: awkawed
2 Replies

3. Shell Programming and Scripting

Match text in a range and copy value

In the files attached, I am trying to: if Files.txt $1 is in the range of Exons.txt $1, then in Files.txt $4 the value from Exons.txt $3 is copied else if no match is found Exons.txt $3 = "Intron" For example, the first value in File.txt $1 is chr1:14895-14944 and is not found in any range... (4 Replies)
Discussion started by: cmccabe
4 Replies

4. Shell Programming and Scripting

Printing rows based on column range

Hello, I have a file with nearly 57K lines. I want to filter the lines based on the range of values in a column. For e.g. print lines whose 3rd filed is >=0.02. Input file: LOC_Os09g32030 LOC_Os02g18880 0.0200037219149773 undirected NA NA LOC_Os03g58630 LOC_Os09g35690 ... (1 Reply)
Discussion started by: Sanchari
1 Replies

5. Shell Programming and Scripting

Copy files given a range of numbers

Hi, I have about 500 files in a directory. The filenames are numbered i.e. 1.dat, 2.dat, 3.dat,...,500.dat. I have 5 other empty directories where I have to copy the files in different range of numbers, for example, 1.dat to 300.dat in dir1, or 200.dat to 500.dat in dir2, another example... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

6. Shell Programming and Scripting

Sum of range of rows and columns in matrix

Hi all, I have a large matrix of 720 x 25. I want to get sum of range of rows and columns. Like, I need sum of all columns and row number 2 to 21, then leaving 22nd row, again sum of all columns and row number 23 to 42 again leaving 43rd row and then sum of 44th to 63. Means I want to add all... (4 Replies)
Discussion started by: CAch
4 Replies

7. UNIX for Dummies Questions & Answers

Extracting rows from a text file if the value of a column falls between a certain range

Hi, I have a file that looks like the following: 10 100080417 rs7915867 ILMN_1343295 12 6243093 7747537 10 100190264 rs2296431 ILMN_1343295 12 6643093 6647537 10 100719451 SNP94374 ILMN_1343295 12 6688093 7599537 ... (1 Reply)
Discussion started by: evelibertine
1 Replies

8. Shell Programming and Scripting

delete rows between closest pattern or range

Hi I am having some problom deleting the lines between two specific lines in a file. need to delete lines between two closest lines. i.e need to find the closest range or pattern in a file with repeating patterns. Sample Input: WARNING <some text in n number of lines> ERROR:2597... (10 Replies)
Discussion started by: sudheer1984
10 Replies

9. Shell Programming and Scripting

Copy range of directory name

Hello folks hope all are doing well, i need to compress directories with range, i have total directories from 000-199 and i want to copy directories from 010 onwards to 020 meants total 11 directories, please suggest what regex will i use. Thanks, Bash (2 Replies)
Discussion started by: learnbash
2 Replies

10. UNIX for Advanced & Expert Users

How can i copy files by date last modifed range?

When I do a ls -lt I get a list of files by date modified from newest to oldest. I would like to be able to copy some files to another directory using a date last modified range (i.e. Apr 30 - May 13) How could I do this? Thanks, Joe (4 Replies)
Discussion started by: geauxsaints
4 Replies
Login or Register to Ask a Question