I'm quite new to unix script, and is having some problems currently.
Say for the following sample project:
The sql result is stored in a file >sql.txt.
The result is shown (sample table):
....and so on
1. Go through every line of the sql result, starting from ID A all the way to the end (row 3 onwards)
2. The result is separated by variable space , ie, width ="5, 4, 5, 7".
3. check value of the Price, Tag of each row, and do processing with it.
I've no gawk, so I cannot use the FIELDWIDTH to set it.
How can I do it with awk/nawk or any other methods?
thanks! appreciate any help and tips
Last edited by Franklin52; 01-08-2009 at 04:51 AM..
Reason: adding code tags
As in how can I separate the row data into its respective field using the column spacing. There is no clear separator like | or ,. Thus, I cannot use commands like FS="|" to clearly get the column values.
As I mentioned before, the fields are referred to $1, $2, $3 and $4, in your scenario:
should print the fields of your file, there's no need to use another fieldseparator.
If you want a formatted output you can use the printf command in awk.
the table i've given above is just a sample..sorry if i'm not clear
As some columns are text field, it is possible that it will contain " " or "," etc, and will not be separated properly.
using FS=" " on above will yield [A 100 te st1 te, st1]
In Linux you can do this to put comma separated data on its own line like this.
sed 's/ */&\n/g' /tmp/ports
sed 's/ */\n/g' /tmp/ports
How do you do this in AIX? It is not working. Is there another way to do this? Something like this.
1, 2, 3, 4
To look like this.
1
2
3
4 (4 Replies)
Hi Forum.
I have the following script that splits a large fixed-width file into smaller multiple fixed-width files based on input segment type.
The main command in the script is:
awk -v search_col_pos=$search_col_pos -v search_str_len=$search_str_len -v segment_type="$segment_type"... (8 Replies)
Discussion started by: pchang
8 Replies
3. Post Here to Contact Site Administrators and Moderators
HI Everyone,
I have below source file
AAA|NAME1|ADDRESS1|300.20
BBB|NAME2|ADDRESS2|400.31
CCC|NAME3|ADDRESS3|300.34
I have requirement where I need to sum up fourth field in above fixed width pipe delimited flat file. When I use below code, it gives me value 1001.00
But I am expecting... (1 Reply)
Hi All,
I am facing issue, to read words in line, line as follow and i want to read word at each comma
1,you,are,two
So i want read like
1
you
are
two
Thanks (1 Reply)
Hi All,
I was wondering how I can convert each line in an input file where fields are separated by variable width spaces into a CSV file. Below is the scenario what I am looking for.
My Input data in inputfile.txt
19 15657 15685 Sr2dReader 107.88 105.51... (4 Replies)
Hi Experts,
I want to Sort the data in fixed width file where i have Header and Footer also in file.
I m using below commad to do the sort based on field satarting from 15 position to 17 position , but it is not ignoring the Header and Footer of the file while sorting. In the output i am... (5 Replies)
hey guys!
i need to read data from a file that are comma separated then reorder them in another file to be generated
for example:
x,y,z
a,b,c
l,m,n
o,p,q
and transform this into:
x,a,l,o
y,b,m,p
z,c,n,q
Will appreciate your fast reply
Regards! (5 Replies)
Hi,
In shell script, I have a variable var = xyz, inn, day, night, calif ....n and I would like to read them in to var1 = xzy, var2 = inn, var3= day, var4 = night....var.
probably in a loop. I would like to read the variables until end of the line. Comma is the delimiter and there's no comma at... (3 Replies)
hi
iam reading data from web page using request socket and curl socket.
now my problem is some the web page containg data as a image so how can i read the data from a image.
thank,inadvance.
sree (3 Replies)
Hi All,
I am having trouble through, I am reading the input from tab delimited file containing several records,
e.g.
line1 field1 field2 field3 so on..
line2 field1 field2 field3 so on..
..
..
on the basis of certain fields for each record in input file, I have to retrieve... (1 Reply)