Sponsored Content
Top Forums Shell Programming and Scripting Split files by pairwise combination Post 302927864 by senhia83 on Saturday 6th of December 2014 05:35:32 PM
Old 12-06-2014
Split files by pairwise combination

I have 2 files

Code:
 
 $ cat  tmp
 A1 File1a B1 File1b
 A2 File2a B2 File2b
 A1 File1a B3 File3b


and

Code:
 
 $ cat  tmp1
 A1/B1 File3
 A1/B1 File4
 A1/B1 File5
 A1/B1 File6
 A1/B1 File7
 A2/B2 File8
 A2/B2 File9
 A2/B2 File10
 A2/B2 File11
 A2/B2 File12
 A2/B2 File13
 A1/B3 File14
 A1/B3 File15
 A1/B3 File16
 A1/B3 File17



I want to split the files having each A, B and A/B combinations , naming the files according to combinations also hardcoding the values A, B and A/B in a third column

Code:
 
 out_A1_B1
  
 A1 File1a A
 B1 File1b B
 A1/B1 File3 A/B
 A1/B1 File4 A/B
 A1/B1 File5 A/B
 A1/B1 File6 A/B
 A1/B1 File7 A/B
  
  
 out_A2_B2
  
 A2 File2a A
 B2 File2b B
 A2/B2 File8 A/B
 A2/B2 File9 A/B
 A2/B2 File10 A/B
 A2/B2 File11 A/B
 A2/B2 File12 A/B
 A2/B2 File13 A/B
  
 out_A1_B3
  
 A1 File1a A
 B3 File3b B
 A1/B3 File14 A/B
 A1/B3 File15 A/B
 A1/B3 File16 A/B
 A1/B3 File17 A/B





What is wrong with my try

Code:
 
 awk '{print $1 FS $2 FS "A""\n"$3 FS $4 FS "B" >> tmp_$1_$2 ; grep "$1/$3" tmp1 >> tmp_$1_$2 }' tmp  
  
 for file in tmp_*
 do
 awk 'NF==2{$3="A/B"; print $0}' $file > out-$file
 done


Last edited by senhia83; 12-06-2014 at 06:50 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

split files into specified number of output files

Hi everyone, I have some large text files that I need to split into a specific number of files of equal size. As far as I know (and I don't really know that much :)) the split command only lets you specify the number of lines or bytes. The files are all of a different size, so the number of... (4 Replies)
Discussion started by: Migrainegirl
4 Replies

2. UNIX for Dummies Questions & Answers

to split gz files

Hi, I want to know how to split a gz file ( with out uncompressing it ) Eg:- split -b 10m file.gz (2 Replies)
Discussion started by: daptal
2 Replies

3. Shell Programming and Scripting

Split a files into many files when condition

Hi Everyone, file.txt +++ a b c +++ d +++ asdf fefe fff Would like to have the output: file1.txt (22 Replies)
Discussion started by: jimmy_y
22 Replies

4. Shell Programming and Scripting

how to calculate all pairwise distances in two dimensions and transform them into a matrix

Hello to all, I am very new in the shell scripting and I need help. I have data for several individuals in several rows followed by a tag and by 5 values per row, with the name of the individual in the first column, e.g.: IND1 H1 12 13 12 15 14 IND2 H2 12 12 15 14 14 IND3 H1 12 15... (2 Replies)
Discussion started by: Bemar
2 Replies

5. UNIX for Dummies Questions & Answers

Extract unique combination of rows from text files

Hi Gurus, I have 100 tab-delimited text files each with 21 columns. I want to extract only 2nd and 5th column from each text file. However, the values in both 2bd and 5th column contain duplicate values but the combination of these values in a row are not duplicate. I want to extract only those... (3 Replies)
Discussion started by: Unilearn
3 Replies

6. Shell Programming and Scripting

Split files

Hi , I have 100 records in a.txt file Need to split the a.txt file in to 5 files 1ST File: ex: My file name should be a1.txt - line count in file should be 1 to 15 2ND File: ex: My file name should be a2.txt - line count in file should be 16 to 40 3ND File: ex: My file name... (1 Reply)
Discussion started by: satish1222
1 Replies

7. Shell Programming and Scripting

Split and rename files

Hello, Need to split files into n number of files and rename the files Example: Input: transaction.txt.1aa transaction.txt.1ab ...... Output: transaction.txt.1 transaction.txt.2 transaction.txt.3 (3 Replies)
Discussion started by: krux_rap
3 Replies

8. UNIX for Beginners Questions & Answers

Split and Rename Split Files

Hello, I need to split a file by number of records and rename each split file with actual filename pre-pended with 3 digit split number. What I have tried is the below command with 2 digit numeric value split -l 3 -d abc.txt F (# Will Produce split Files as F00 F01 F02) How to produce... (19 Replies)
Discussion started by: techedipro
19 Replies

9. UNIX for Beginners Questions & Answers

Automate splitting of files , scp files as each split completes and combine files on target server

i use the split command to split a one terabyte backup file into 10 chunks of 100 GB each. The files are split one after the other. While the files is being split, I will like to scp the files one after the other as soon as the previous one completes, from server A to Server B. Then on server B ,... (2 Replies)
Discussion started by: malaika
2 Replies

10. UNIX for Beginners Questions & Answers

Create 'n' number random pairwise combination of words

File 1 contains the list of words that needed to be randomly paired: Tiger Cat Fish Frog Dog Mouse Elephant Monkey File 2 contains the pairs that should not be used (in any solution) during random pairing. Elephant-Dog Cat-Fish Monkey-Frog Dog-Elephant, Fish-Cat, Frog-Monkey... (1 Reply)
Discussion started by: sammy777888
1 Replies
OD(1)									FSF								     OD(1)

NAME
od - dump files in octal and other formats SYNOPSIS
od [OPTION]... [FILE]... od --traditional [FILE] [[+]OFFSET [[+]LABEL]] DESCRIPTION
Write an unambiguous representation, octal bytes by default, of FILE to standard output. With more than one FILE argument, concatenate them in the listed order to form the input. With no FILE, or when FILE is -, read standard input. All arguments to long options are mandatory for short options. -A, --address-radix=RADIX decide how file offsets are printed -j, --skip-bytes=BYTES skip BYTES input bytes first -N, --read-bytes=BYTES limit dump to BYTES input bytes -s, --strings[=BYTES] output strings of at least BYTES graphic chars -t, --format=TYPE select output format or formats -v, --output-duplicates do not use * to mark line suppression -w, --width[=BYTES] output BYTES bytes per output line --traditional accept arguments in traditional form --help display this help and exit --version output version information and exit Traditional format specifications may be intermixed; they accumulate: -a same as -t a, select named characters -b same as -t oC, select octal bytes -c same as -t c, select ASCII characters or backslash escapes -d same as -t u2, select unsigned decimal shorts -f same as -t fF, select floats -h same as -t x2, select hexadecimal shorts -i same as -t d2, select decimal shorts -l same as -t d4, select decimal longs -o same as -t o2, select octal shorts -x same as -t x2, select hexadecimal shorts For older syntax (second call format), OFFSET means -j OFFSET. LABEL is the pseudo-address at first byte printed, incremented when dump is progressing. For OFFSET and LABEL, a 0x or 0X prefix indicates hexadecimal, suffixes may be . for octal and b for multiply by 512. TYPE is made up of one or more of these specifications: a named character c ASCII character or backslash escape d[SIZE] signed decimal, SIZE bytes per integer f[SIZE] floating point, SIZE bytes per integer o[SIZE] octal, SIZE bytes per integer u[SIZE] unsigned decimal, SIZE bytes per integer x[SIZE] hexadecimal, SIZE bytes per integer SIZE is a number. For TYPE in doux, SIZE may also be C for sizeof(char), S for sizeof(short), I for sizeof(int) or L for sizeof(long). If TYPE is f, SIZE may also be F for sizeof(float), D for sizeof(double) or L for sizeof(long double). RADIX is d for decimal, o for octal, x for hexadecimal or n for none. BYTES is hexadecimal with 0x or 0X prefix, it is multiplied by 512 with b suffix, by 1024 with k and by 1048576 with m. Adding a z suffix to any type adds a display of printable characters to the end of each line of output. --string without a number implies 3. --width without a number implies 32. By default, od uses -A o -t d2 -w 16. AUTHOR
Written by Jim Meyering. REPORTING BUGS
Report bugs to <bug-coreutils@gnu.org>. COPYRIGHT
Copyright (C) 2002 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. SEE ALSO
The full documentation for od is maintained as a Texinfo manual. If the info and od programs are properly installed at your site, the com- mand info od should give you access to the complete manual. od (coreutils) 4.5.3 February 2003 OD(1)
All times are GMT -4. The time now is 01:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy