04-28-2009
awk sed cut? to rearrange random number of fields into 3 fields
I'm working on formatting some attendance data to meet a vendors requirements to upload to their system. With some help on the forums here, I have the data close. But they've since changed what they want.
The vendor wants me to submit three fields to them. Field 1 is the studentid field, field 2 is to be the building number and field 3 is a comma (and space char) delimited field holding periods.
This is what I have out of our records system now. Basically studentid, the periods, then the building number last. Each student is only listed once, so field 1 is unique in the input file 'absentees'.
250,1,2,3,45
255,2,4,6,8,10,45
1005,1,50
2099,1,2,51
I'd like to move the last field to the second position. Then enclose the remaining fields into one field with double quotes. Only if more than one period though (see third record for example of a record with only 1 period). So basically I need to get it looking like this (header row just fyi):
sid,bldg,periods
250,45,"1, 2, 3"
255,45,"2, 4, 6, 8, 10"
1005,50,1
2099,51,"1, 2"
I've used sed and cut to rearrange the order of fields when the number of fields are fixed. Not sure how to do it with a random number of fields though. Really not sure how to get the double quotes in there with comma and a space char.
I'm on hp-ux, so just awk is avail to me. (no gawk or nawk)
thanks in advance for any suggestions
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hello all, I'm working on an attendance callout script for a school district. I need to change our current layout for the vendor. Currently the data is in the form of:
studentid,period,building,
Heres a sample of some made up records:
500,1,30,
500,2,30,
500,3,30,
500,6,30,... (7 Replies)
Discussion started by: axo959
7 Replies
2. UNIX for Dummies Questions & Answers
hi forums
i need help with a little problem i am having.
i need to count the number of fields that are in a saved variable so i can use that number to make a different function work properly.
is there a way of doing this without using SED/AWK?
anything would be greatly appreciated (4 Replies)
Discussion started by: strasner
4 Replies
3. Shell Programming and Scripting
Hi Everyone,
# cat 1.txt
1321631,77770132976455,19,20091001011859,20091001011907
1321631,77770132976455,19,20091001011859,20091001011907
1321631,77770132976455,19,20091001011859,20091001011907
# cat 1.txt | awk -F, '{OFS=",";print $1,$3,$4,$5}'
1321631,19,20091001011859,20091001011907... (7 Replies)
Discussion started by: jimmy_y
7 Replies
4. Shell Programming and Scripting
Hi experts,
I need to print the first field first then last two fields should come next and then i need to print rest of the fields.
Input :
a1,abc,jsd,fhf,fkk,b1,b2
a2,acb,dfg,ghj,b3,c4
a3,djf,wdjg,fkg,dff,ggk,d4,d5
Expected output:
a1,b1,b2,abc,jsd,fhf,fkk... (6 Replies)
Discussion started by: 100bees
6 Replies
5. Shell Programming and Scripting
Hi,
I am required to arrange columns of a file i.e make the 15th column into the 1st column.
I am doing
awk 'begin {fs=ofs=","} {print $15,$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14}' ad.data>ad.csv
the problem is that column 15 gets to column 1 but it is not comma separated with the... (10 Replies)
Discussion started by: seddoubt
10 Replies
6. Shell Programming and Scripting
I'm trying to compare 2 files for differences in a selct number of fields. When differnces are found it will write the whole record of the second file including appending '|C' out to a delta file. Each record will have 20 fields, but only want to do comparison of 1st 15 fields. The 1st field of... (7 Replies)
Discussion started by: sljnk
7 Replies
7. Shell Programming and Scripting
Hi
I have a file as below
<field1> <field2> <field3> ... <field_num1> <field_num2>
Trying to sort based on difference of <field_num1> and <field_num2> in desceding order and print all fields.
I tried this and it doesn't sort on the difference field .. Appreciate your help.
cat... (9 Replies)
Discussion started by: newstart
9 Replies
8. Shell Programming and Scripting
For an Output like below
Input : <Subject A="I" B="1039502" C="2015-06-30" D="010101010101">
Output : <Subject D="010101010101" B="1039502" C="2015-06-30" A="I">
I have been using something like below but not getting the desired output :
awk -F ' ' '/Subject/ BEGIN{OFS=" ";}... (19 Replies)
Discussion started by: arunkesi
19 Replies
9. Shell Programming and Scripting
I want to rearrange the fields of delimited text file after sorting first line (only):
input file:
a_13;a_2;a_1;a_10
13;2;1;10
the result should be:
a_1;a_2;a_10;a_13
1;2;10;13
any help would be appreciated
andy (20 Replies)
Discussion started by: andy2000
20 Replies
10. UNIX for Beginners Questions & Answers
Hi,
Below are the sample files. x.txt is from an Excel file that is a list of users from Windows and y.txt is a list of database account.
$ head -500 x.txt y.txt
==> x.txt <==
TEST01 APP_USER_PROFILE
USER03 APP_USER_PROFILE
TEST02 APP_USER_EXP_PROFILE
TEST04 APP_USER_PROFILE
USER01 ... (3 Replies)
Discussion started by: newbie_01
3 Replies
LEARN ABOUT DEBIAN
deb-origin
deb-origin(5) Debian deb-origin(5)
NAME
deb-origin - Vendor-specific information files
SYNOPSIS
/etc/dpkg/origins/filename
DESCRIPTION
The files in /etc/dpkg/origins can provide information about various vendors who are providing Debian packages. They contain a number of
fields, or comments when the line starts with '#'. Each field begins with a tag, such as Vendor or Parent, followed by a colon and the
body of the field. Fields are delimited only by field tags. In other words, field text may be multiple lines in length, but the tools will
join lines when processing the body of the field.
REQUIRED FIELDS
Vendor: vendor-name
The value of this field determines the vendor name.
OPTIONAL FIELDS
Vendor-URL: vendor-url
The value of this field determines the vendor URL.
Bugs: bug-url
The value of this field determines the type and address of the bug tracking system used by this vendor. It can be a mailto URL or a
debbugs URL (e.g., debbugs://bugs.debian.org/).
Parent: vendor-name
The value of this field determines the vendor name of the vendor that this vendor derives from.
EXAMPLE
Vendor: Debian
Vendor-URL: http://www.debian.org/
Bugs: debbugs://bugs.debian.org
SEE ALSO
dpkg-vendor(1)
Debian Project 2011-11-10 deb-origin(5)