Sponsored Content
Top Forums Shell Programming and Scripting awk regexp to print repetitive pattern Post 302977321 by yifangt on Friday 15th of July 2016 07:29:17 PM
Old 07-15-2016
Thanks Don and all!
What I was doing is to combined two files (each half million lines) by a matching column, if no match (0.01%), make up the missing fields with the "-", which triggered me asking if there is regex for my purpose:
Code:
$ cat file2
XLOC_000001 TCONS_00000001 LOC_Os02g39790.2 47.273 55 24 2 3855 4016 335 385 3.60e-04  
XLOC_000001 TCONS_00000002 LOC_Os02g39790.2 47.273 55 24 2 2368 2529 335 385 2.35e-04  
XLOC_000001 TCONS_00000007 LOC_Os02g39790.2 47.273 55 24 2 3553 3714 335 385 3.09e-04  
XLOC_000001 TCONS_00000009 LOC_Os02g39790.2 47.273 55 24 2 5083 5244 335 385 2.83e-04  
XLOC_000001 TCONS_00000011 LOC_Os02g39790.2 47.273 55 24 2 2200 2361 335 385 2.28e-04   
$ cat file1
TCONS_00000001    W5GKA3_WHEAT
TCONS_00000002    W5GKA3_WHEAT
TCONS_00000011    I1IBH3_BRADI
TCONS_00000009    W5GKA3_WHEAT
TCONS_00000005    I1IBH3_BRADI
TCONS_00000006    I1IBH3_BRADI
TCONS_00000007    W5GKA3_WHEAT

Code:
$ awk 'NR==FNR {A[$2]=$0; next}; {if (A[$1]) print $0, A[$1]; else print $0, "-\t-\t-\t-\t-\t-\t-\t-\t-\t-\t-\t-" }' file2 file1
TCONS_00000001    W5GKA3_WHEAT XLOC_000001 TCONS_00000001 LOC_Os02g39790.2 47.273 55 24 2 3855 4016 335 385 3.60e-04  
TCONS_00000002    W5GKA3_WHEAT XLOC_000001 TCONS_00000002 LOC_Os02g39790.2 47.273 55 24 2 2368 2529 335 385 2.35e-04  
TCONS_00000011    I1IBH3_BRADI XLOC_000001 TCONS_00000011 LOC_Os02g39790.2 47.273 55 24 2 2200 2361 335 385 2.28e-04   
TCONS_00000009    W5GKA3_WHEAT XLOC_000001 TCONS_00000009 LOC_Os02g39790.2 47.273 55 24 2 5083 5244 335 385 2.83e-04  
TCONS_00000005    I1IBH3_BRADI -    -    -    -    -    -    -    -    -    -    -    -
TCONS_00000006    I1IBH3_BRADI -    -    -    -    -    -    -    -    -    -    -    -
TCONS_00000007    W5GKA3_WHEAT XLOC_000001 TCONS_00000007 LOC_Os02g39790.2 47.273 55 24 2 3553 3714 335 385 3.09e-04

Typing that long string "-\t" repetitively looks dull, and I felt dizzy counting the number of tabs while typing. I made mistakes and need re-run a couple of times to get it correct! So I thought if there is regex I could avoid the mistake.
Thanks again!

Last edited by yifangt; 07-15-2016 at 08:32 PM.. Reason: typos
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk how to print if the search pattern contains speace

the data file is as below: > cat master.cnf /usr| location for usr|5 /src/ver1| version 1 |10 /src/ver2/log| ver 2 log |25 /src/sys/apps/log| Application log for sys|36 /src/sys/apps/conf| configuration location for app|45 /src/sys/apps/bin| binary location app|55my script is as below: ... (1 Reply)
Discussion started by: McLan
1 Replies

2. UNIX for Dummies Questions & Answers

print the line immediately after a regexp; but regexp is a sentence

Good Day, Im new to scripting especially awk and sed. I just would like to ask help from you guys about a sed command that prints the line immediately after a regexp, but not the line containing the regexp. sed -n '/regexp/{n;p;}' filename What if my regexp is 3 word or a sentence. Im... (3 Replies)
Discussion started by: ownins
3 Replies

3. Shell Programming and Scripting

Perl Repetitive Pattern Matching

Problem: GIVEN ======= my $sql="INSERT INTO table_nm(a, b, b, d, e, f , g) VALUES (2046, TODAY, 'Change Subscription Name', '00000000000002000000000000000000000000000000000000', '00000000000001000000000000000000000000000000000000', '00000000000000000000000000000000000000000000000000', 1);... (2 Replies)
Discussion started by: Niroj
2 Replies

4. Shell Programming and Scripting

Use to awk to match pattern, and print the pattern

Hi, I know how to use awk to search some expressions like five consecutive numbers, , this is easy. However, how do I make awk print the pattern that is been matched? For example: input: usa,canada99292,japan222,france59664,egypt223 output:99292,59664 (6 Replies)
Discussion started by: grossgermany
6 Replies

5. Shell Programming and Scripting

Print lines between two repetitive patterns

Hi users I have one file which has number of occurrence of one pattern examples Adjustmenttype,11 xyz 10 dwe 9 abd 13 def 14 Adjustmenttype,11 xyz 24 dwe 34 abd 35 def 11 nmb 12 Adjustmenttype, not eleven .... ... ... (2 Replies)
Discussion started by: eranmoh
2 Replies

6. Shell Programming and Scripting

print pattern between two variables awk sed

I am trying to print text between two variables in a file I have tried the following things but none seem to work: awk ' /'$a'/ {flag=1;next} /'$b'/{flag=0} flag { print }' file and also sed "/$a/,/$b/p" file But none seem to work Any Ideas? Thanks in Advance (5 Replies)
Discussion started by: forumbaba
5 Replies

7. Shell Programming and Scripting

AWK: Grep Pattern and print help

I wanted to get outcome from a big file with pattern quoted: Line FSP LSP SR RL Test1 100 300 4 4000 Test2 1 300 2 300 Any help is greatly appreciated. Thank you. (15 Replies)
Discussion started by: rtsiahaan
15 Replies

8. Shell Programming and Scripting

awk, sed or perl regexp to print values from file

Hello all According to the following file (orignal one contains 200x times the same structure...) I was wondering if someone could help me to print <byte>??</byte> values example, running this script/command like ./script.sh xxapp I would expect as output: 102 116 112 ./script.sh xxapp2... (2 Replies)
Discussion started by: cabrao
2 Replies

9. Shell Programming and Scripting

Help with using awk to print pattern/occurence

Hi, Do anybody know how to use awk to count the pattern at specific column? Input file M2A928K 419 ath-miR159a,gma-miR159a-3p,ptc-miR159a 60 miR235a . . Output file M2A928K 419 ath-miR159a,gma-miR159a-3p,ptc-miR159a 60 miR235a 3 . . I plan to count how many "miR" in column 3... (2 Replies)
Discussion started by: cpp_beginner
2 Replies

10. UNIX for Beginners Questions & Answers

awk or sed to print the character from the previous line after the regexp match

Hi All, I need to print the characters in the previous line just before the regular expression match Please have a look at the input file as attached I need to match the regular expression ^ with the character of the previous like and also the pin numbers and the output file should be like... (6 Replies)
Discussion started by: kshitij
6 Replies
iconv_8859-5(5)                                         Standards, Environments, and Macros                                        iconv_8859-5(5)

NAME
iconv_8859-5 - code set conversion tables for ISO 8859-5 (Cyrillic) DESCRIPTION
The following code set conversions are supported: +-------------------------------------------------------------------------+ | Code Set Conversions Supported | +--------------+--------+--------------+--------+-------------------------+ | Code |Symbol |Target Code |Symbol | Target Output | +--------------+--------+--------------+--------+-------------------------+ |ISO 8859-5 |iso5 |KOI8-R |koi8 | KOI8-R | +--------------+--------+--------------+--------+-------------------------+ |ISO 8859-5 |iso5 |PC Cyrillic |alt | Alternative PC Cyrillic | +--------------+--------+--------------+--------+-------------------------+ |ISO 8859-5 |iso5 |MS 1251 |win5 | Windows Cyrillic | +--------------+--------+--------------+--------+-------------------------+ |ISO 8859-5 |iso5 |Mac Cyrillic |mac | Macintosh Cyrillic | +--------------+--------+--------------+--------+-------------------------+ CONVERSIONS
The conversions are performed according to the following tables. All values in the tables are given in octal. ISO 8859-5 to KOI8-R For the conversion of ISO 8859-5 to KOI8-R, all characters not in the following table are mapped unchanged. +-----------------------------------------------------------------+ | | Conversions|Performed | | | ISO 8859-5 | KOI8-R | ISO 8859-5 | KOI8-R | |24 | 4 |320 |301 | |241 | 263 |321 |302 | |242 | 261 |322 |327 | |243 | 262 |323 |307 | |244 | 264 |324 |304 | |245 | 265 |325 |305 | |246 | 266 |327 |332 | |247 | 267 |330 |311 | |250 | 270 |331 |312 | |251 | 271 |332 |313 | |252 | 272 |333 |314 | |253 | 273 |334 |315 | |254 | 274 |335 |316 | |256 | 276 |336 |317 | |257 | 277 |337 |320 | |260 | 341 |340 |322 | |261 | 342 |341 |323 | |262 | 367 |342 |324 | |263 | 347 |343 |325 | |264 | 344 |344 |306 | |265 | 345 |345 |310 | |266 | 366 |346 |303 | |267 | 372 |347 |336 | |270 | 351 |350 |333 | |271 | 352 |351 |335 | |272 | 353 |352 |337 | |273 | 354 |353 |331 | |274 | 355 |354 |330 | |275 | 356 |355 |334 | |276 | 357 |356 |300 | |277 | 360 |357 |321 | |300 | 362 |360 |260 | |301 | 363 |361 |243 | |302 | 364 |362 |241 | |303 | 365 |363 |242 | |304 | 346 |364 |244 | |305 | 350 |365 |245 | |306 | 343 |366 |246 | |307 | 376 |367 |247 | |310 | 373 |370 |250 | |311 | 375 |371 |251 | |312 | 377 |372 |252 | |313 | 371 |373 |253 | |314 | 370 |374 |254 | |315 | 374 |375 |255 | |316 | 340 |376 |256 | |317 | 361 | | | +---------------+----------------+----------------+---------------+ ISO 8859-5 to PC Cyrillic For the conversion of ISO 8859-5 to PC Cyrillic, all characters not in the following table are mapped unchanged. +-----------------------------------------------------------------+ | | Conversions|Performed | | | ISO 8859-5 | PC Cyrillic | ISO 8859-5 | PC Cyrillic | |24 | 4 |307 |227 | |200-240 | 40 |310 |230 | |241 | 360 |311 |231 | |242-254 | 40 |312 |232 | |255 | 260 |313 |233 | |256-257 | 40 |314 |234 | |260 | 200 |315 |235 | |261 | 201 |316 |236 | |262 | 202 |317 |237 | |263 | 203 |320 |240 | |264 | 204 |321 |241 | |265 | 205 |322 |242 | |266 | 206 |323 |243 | |267 | 207 |324 |244 | |270 | 210 |325 |245 | |271 | 211 |326 |246 | |272 | 212 |327 |247 | |273 | 213 |330 |250 | |274 | 214 |331 |251 | |275 | 215 |332 |252 | |276 | 216 |333 |253 | |277 | 217 |334 |254 | |300 | 220 |335 |255 | |301 | 221 |336 |256 | |302 | 222 |337 |257 | |303 | 223 |360-374 |40 | |304 | 224 |375 |260 | |305 | 225 |376 |40 | |306 | 226 |365 |40 | +---------------+----------------+----------------+---------------+ ISO 8859-5 to MS 1251 For the conversion of ISO 8859-5 to MS 1251, all characters not in the following table are mapped unchanged. +-----------------------------------------------------------------+ | | Conversions|Performed | | | ISO 8859-5 | MS 1251 | ISO 8859-5 | MS 1251 | |24 | 4 |317 |337 | |200-237 | 40 |320 |340 | |241 | 250 |321 |341 | |242 | 200 |322 |342 | |243 | 201 |323 |343 | |244 | 252 |324 |344 | |245 | 275 |325 |345 | |246 | 262 |326 |346 | |247 | 257 |327 |347 | |250 | 243 |330 |350 | |251 | 212 |331 |351 | |252 | 214 |332 |352 | |253 | 216 |333 |353 | |254 | 215 |334 |354 | |255 | 210 |335 |355 | |256 | 241 |336 |356 | |257 | 217 |337 |357 | |260 | 300 |340 |360 | |261 | 301 |341 |361 | |262 | 302 |342 |362 | |263 | 303 |343 |363 | |264 | 304 |344 |364 | |265 | 305 |345 |365 | |266 | 306 |346 |366 | |267 | 307 |347 |367 | |270 | 310 |350 |370 | |271 | 311 |351 |371 | |272 | 312 |352 |372 | |273 | 313 |353 |373 | |274 | 314 |354 |374 | |275 | 315 |355 |375 | |276 | 316 |356 |376 | |277 | 317 |357 |377 | |300 | 320 |360 |271 | |301 | 321 |361 |270 | |302 | 322 |362 |220 | |303 | 323 |363 |203 | |304 | 324 |364 |272 | |305 | 325 |365 |276 | |306 | 326 |366 |263 | |307 | 327 |367 |277 | |310 | 330 |370 |274 | |311 | 331 |371 |232 | |312 | 332 |372 |234 | |313 | 333 |373 |236 | |314 | 334 |374 |235 | |315 | 335 |375 |210 | |316 | 336 |376 |242 | |376 | 331 | | | +---------------+----------------+----------------+---------------+ ISO 8859-5 to Mac Cyrillic For the conversion of ISO 8859-5 to Mac Cyrillic, all characters not in the following table are mapped unchanged. +-----------------------------------------------------------------+ | | Conversions|Performed | | | ISO 8859-5 | Mac Cyrillic | ISO 8859-5 | Mac Cyrillic | |24 | 4 |317 |237 | |200-237 | 40 |320 |340 | |240 | 312 |321 |341 | |241 | 335 |322 |342 | |242 | 253 |323 |343 | |243 | 256 |324 |344 | |244 | 270 |325 |345 | |245 | 301 |326 |346 | |246 | 247 |327 |347 | |247 | 272 |330 |350 | |250 | 267 |331 |351 | |251 | 274 |332 |352 | |252 | 276 |333 |353 | |253 | 40 |334 |354 | |254 | 315 |335 |355 | |255 | 40 |336 |356 | |256 | 330 |337 |357 | |257 | 332 |340 |360 | |260 | 200 |341 |361 | |261 | 201 |342 |362 | |262 | 202 |343 |363 | |263 | 203 |344 |364 | |264 | 204 |345 |365 | |265 | 205 |346 |366 | |266 | 206 |347 |367 | |267 | 207 |350 |370 | |270 | 210 |351 |371 | |271 | 211 |352 |372 | |272 | 212 |353 |373 | |273 | 213 |354 |374 | |274 | 214 |355 |375 | |275 | 215 |356 |376 | |276 | 216 |357 |337 | |277 | 217 |360 |334 | |300 | 220 |361 |336 | |301 | 221 |362 |254 | |302 | 222 |363 |257 | |303 | 223 |364 |271 | |304 | 224 |365 |317 | |305 | 225 |366 |264 | |306 | 226 |367 |273 | |307 | 227 |370 |300 | |310 | 230 |371 |275 | |311 | 231 |372 |277 | |312 | 232 |373 |40 | |313 | 233 |374 |316 | |314 | 234 |375 |40 | |315 | 235 |376 |331 | |316 | 236 | | | +---------------+----------------+----------------+---------------+ 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_8859-5(5)
All times are GMT -4. The time now is 09:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy