Sponsored Content
Top Forums Shell Programming and Scripting Print every 5 4th column values as separate row with different first column Post 302771410 by Don Cragun on Wednesday 20th of February 2013 02:47:45 PM
Old 02-20-2013
This seems to do what you want:
Code:
awk 'NR % 5 == 1 {
        # 1st line in a set of 5 lines.
        # Set the saved output string to the 4th field in this line.
        o = $4
        next
}       
NR % 5 {# 2nd through 4th line in a set of 5 lines.
        # Add the 4th field in this line to the saved output string.
        o = o " " $4
        next
}       
{       # 5th line in a set of 5 lines.
        # Print the result of processing this set of 5 lines.
        printf("peak%d %s %s\n", ++oc, o, $4)
}       
END {   # If the input file had less than 5 lines in the last set, print the
        # partial set.
        if(NR % 5) printf("peak%d %s\n", ++oc, o)
}' file

If you are using a Solaris/SusOS system, use /usr/xpg4/bin/awk or nawk instead of awk.
This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to read the column and print the values under that column

hi all:b:, how to read the column and print the values under that column ...?? file1 have something like this cat file1 ======= column1, column2,date,column3,column4..... 1, 23 , 12/02/2008,...... 2, 45, 14/05/2008,..... 3, 56, 16/03/2008,..... cat file2 =======... (6 Replies)
Discussion started by: gemini106
6 Replies

2. Shell Programming and Scripting

print unique values of a column and sum up the corresponding values in next column

Hi All, I have a file which is having 3 columns as (string string integer) a b 1 x y 2 p k 5 y y 4 ..... ..... Question: I want get the unique value of column 2 in a sorted way(on column 2) and the sum of the 3rd column of the corresponding rows. e.g the above file should return the... (6 Replies)
Discussion started by: amigarus
6 Replies

3. Shell Programming and Scripting

Remove duplicates within row and separate column

Hi all I have following kind of input file ESR1 PA156 leflunomide PA450192 leflunomide CHST3 PA26503 docetaxel Pa4586; thalidomide Pa34958; decetaxel docetaxel docetaxel I want to remove duplicates and I want to separate anything before and after PAxxxx entry into columns or... (1 Reply)
Discussion started by: manigrover
1 Replies

4. UNIX for Dummies Questions & Answers

awk to print first row with forth column and last row with fifth column in each file

file with this content awk 'NR==1 {print $4} && NR==2 {print $5}' file The error is shown with syntax error; what can be done (4 Replies)
Discussion started by: cdfd123
4 Replies

5. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

6. Shell Programming and Scripting

Print row on 4th column to all row

Dear All, I have input : SEG901 5173 9005 5740 SEG902 5227 5284 SEG903 5284 5346 SEG904 5346 9010 SEG905 5400 5456 SEG906 5456 5511 SEG907 5511 9011 SEG908 5572 9015 SEG909 5622 9020 SEG910 5678 5739 SEG911 5739 5796 SEG912 5796 9025 ... (3 Replies)
Discussion started by: attila
3 Replies

7. Shell Programming and Scripting

Read 4th column and print those many rows

Hi, My input file chr1 3217769 3217789 2952725-5 255 + chr1 3260455 3260475 2434087-6 255 - My desired output chr1 3217769 3217789 2952725-1 255 + chr1 3217769 3217789 2952725-2 255 + chr1 3217769 3217789 2952725-3 255 + chr1 3217769 3217789 2952725-4 255 +... (7 Replies)
Discussion started by: jacobs.smith
7 Replies

8. Shell Programming and Scripting

Changing values only in 3rd column and 4th column

#cat file testing test! nipw asdkjasjdk ok! what !ok host server1 check_ssh_disk!102.56.1.101!30!50!/ other host server 2 des check_ssh_disk!192.6.1.10!40!30!/ #grep check file| awk -F! '{print $3,$4}'|awk '{gsub($1,"",$1)}1' 50 30 # Output: (6 Replies)
Discussion started by: kenshinhimura
6 Replies

9. Shell Programming and Scripting

Print first row of column a, last row of column b if column a has the same value

I have a table with this structure: cola colb colc 1 19 lemon 20 31 lemon 32 100 lemon 159 205 cherries 210 500 cherries and need to parse it into this format: cola colb colc 1 100 lemon 159 500 cherries So I need the first row of cola and the last row of colb if colc has the... (3 Replies)
Discussion started by: coppuca
3 Replies

10. UNIX for Beginners Questions & Answers

If pattern in column 3 matches pattern in column 2 (any row), print value in column 1

Hi all, I have searched and searched, but I have not found a solution that quite fits what I am trying to do. I have a long list of data in three columns. Below is a sample: 1,10,8 2,12,10 3,13,12 4,14,14 5,15,16 6,16,18 Please use code tags What I need to do is as follows: If a... (4 Replies)
Discussion started by: bleedingturnip
4 Replies
iconv_852(5)						Standards, Environments, and Macros					      iconv_852(5)

NAME
iconv_852 - code set conversion tables for MS 852 (MS-DOS Latin 2) DESCRIPTION
The following code set conversions are supported: +--------------------------------------------------------------------+ | Code Set Conversions Supported | +--------------+--------+--------------+--------+--------------------+ | Code |Symbol |Target Code |Symbol | Target Output | +--------------+--------+--------------+--------+--------------------+ |MS 852 |dos2 |ISO 8859-2 |iso2 | ISO Latin 2 | +--------------+--------+--------------+--------+--------------------+ |MS 852 |dos2 |MS 1250 |win2 | Windows Latin 2 | +--------------+--------+--------------+--------+--------------------+ |MS 852 |dos2 |Mazovia |maz | Mazovia | +--------------+--------+--------------+--------+--------------------+ |MS 852 |dos2 |DHN |dhn | Dom Handlowy Nauki | +--------------+--------+--------------+--------+--------------------+ CONVERSIONS
The conversions are performed according to the following tables. All values in the tables are given in octal. MS 852 to ISO 8859-2 For the conversion of MS 852 to ISO 8859-2, all characters not in the following table are mapped unchanged. +-----------------------------------------------------------------+ | | Conversions|Performed | | | MS 852 | ISO 8859-2 | MS 852 | ISO 8859-2 | |24-177 | 40 |271-274 |40 | |200 | 307 |275 |257 | |201 | 374 |276 |277 | |202 | 351 |277-305 |40 | |203 | 342 |306 |303 | |204 | 344 |307 |343 | |205 | 371 |310-316 |40 | |206 | 346 |317 |244 | |207 | 347 |320 |360 | |210 | 263 |321 |320 | |211 | 353 |322 |317 | |212 | 325 |323 |313 | |213 | 365 |324 |357 | |214 | 356 |325 |322 | |215 | 254 |326 |315 | |216 | 304 |327 |316 | |217 | 306 |330 |354 | |220 | 311 |331-334 |40 | |221 | 305 |335 |336 | |222 | 345 |336 |331 | |223 | 364 |337 |40 | |224 | 366 |340 |323 | |225 | 245 |341 |337 | |226 | 265 |342 |324 | |227 | 246 |343 |321 | |230 | 266 |344 |361 | |231 | 326 |345 |362 | |232 | 334 |346 |251 | |233 | 253 |347 |271 | |234 | 273 |350 |300 | |235 | 243 |351 |332 | |236 | 327 |352 |340 | |237 | 350 |353 |333 | |240 | 341 |354 |375 | |241 | 355 |355 |335 | |242 | 363 |356 |376 | |243 | 372 |357 |264 | |244 | 241 |360 |255 | |245 | 261 |361 |275 | |246 | 256 |362 |262 | |247 | 276 |363 |267 | |250 | 312 |364 |242 | |251 | 352 |365 |247 | |252 | 40 |366 |367 | |253 | 274 |367 |270 | |254 | 310 |370 |260 | |255 | 272 |371 |250 | |256-264 | 40 |372 |377 | |265 | 301 |374 |330 | |266 | 302 |375 |370 | |267 | 314 |376 |40 | |270 | 252 | | | +---------------+----------------+----------------+---------------+ MS 852 to MS 1250 For the conversion of MS 852 to MS 1250, all characters not in the following table are mapped unchanged. +-----------------------------------------------------------------+ | | Conversions|Performed | | | MS 852 | MS 1250 | MS 852 | MS 1250 | |200 | 307 |270 |252 | |201 | 374 |271-274 |40 | |202 | 351 |275 |257 | |203 | 342 |276 |277 | |204 | 344 |277-305 |40 | |205 | 371 |306 |303 | |206 | 346 |307 |343 | |207 | 347 |310-316 |40 | |210 | 263 |317 |244 | |211 | 353 |320 |360 | |212 | 325 |321 |320 | |213 | 365 |322 |317 | |214 | 356 |323 |313 | |215 | 217 |324 |357 | |216 | 304 |325 |322 | |217 | 306 |326 |315 | |220 | 311 |327 |316 | |221 | 305 |330 |354 | |222 | 345 |331-334 |40 | |223 | 364 |335 |336 | |224 | 366 |336 |331 | |225 | 274 |337 |40 | |226 | 276 |340 |323 | |227 | 214 |341 |337 | |230 | 234 |342 |324 | |231 | 326 |343 |321 | |232 | 334 |344 |361 | |233 | 215 |345 |362 | |234 | 235 |346 |212 | |235 | 243 |347 |232 | |236 | 327 |350 |300 | |237 | 350 |351 |332 | |240 | 341 |352 |340 | |241 | 355 |353 |333 | |242 | 363 |354 |375 | |243 | 372 |355 |335 | |244 | 245 |356 |376 | |245 | 271 |357 |264 | |246 | 216 |360 |255 | |247 | 236 |361 |275 | |250 | 312 |362 |262 | |251 | 352 |363 |241 | |252 | 254 |364 |242 | |253 | 237 |365 |247 | |254 | 310 |366 |367 | |255 | 272 |367 |270 | |256 | 253 |370 |260 | |257 | 273 |371 |250 | |260-264 | 40 |372 |377 | |265 | 301 |374 |330 | |266 | 302 |375 |370 | |267 | 314 |376 |40 | +---------------+----------------+----------------+---------------+ MS 852 to Mazovia For the conversion of MS 852 to Mazovia, all characters not in the following table are mapped unchanged. +-----------------------------------------------------------------+ | | Conversions|Performed | | | MS 852 | Mazovia | MS 852 | Mazovia | |205 | 40 |246-247 |40 | |206 | 215 |250 |220 | |210 | 222 |251 |221 | |212-213 | 40 |253 |246 | |215 | 240 |254-270 |40 | |217 | 225 |275 |241 | |220-226 | 40 |276 |247 | |227 | 230 |306-336 |40 | |230 | 236 |340 |243 | |233-234 | 40 |342 |40 | |235 | 234 |343 |245 | |236-243 | 40 |344 |244 | |244 | 217 |345-375 |40 | |245 | 206 | | | +---------------+----------------+----------------+---------------+ MS 852 to DHN For the conversion of MS 852 to DHN, all characters not in the following table are mapped unchanged. +-----------------------------------------------------------------+ | | Conversions|Performed | | | MS 852 | DHN | MS 852 | DHN | |200-205 | 40 |244 |200 | |206 | 212 |245 |211 | |207 | 40 |246-247 |40 | |210 | 214 |250 |202 | |211-214 | 40 |251 |213 | |215 | 207 |253 |220 | |216 | 40 |254-270 |40 | |217 | 201 |275 |210 | |220-226 | 40 |276 |221 | |227 | 206 |306-336 |40 | |230 | 217 |340 |205 | |233-234 | 40 |342 |40 | |235 | 203 |343 |204 | |236-237 | 40 |344 |215 | |242 | 216 |345-375 |40 | |252 | 254 | | | +---------------+----------------+----------------+---------------+ FILES
/usr/lib/iconv/*.so conversion modules /usr/lib/iconv/*.t conversion tables /usr/lib/iconv/iconv_data list of conversions supported by conversion tables SEE ALSO
iconv(1), iconv(3C), iconv(5) SunOS 5.10 18 Apr 1997 iconv_852(5)
All times are GMT -4. The time now is 05:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy