Sponsored Content
Top Forums Shell Programming and Scripting Get 4 character each from 2 different fields concatenate and add as a new field Post 302341913 by summer_cherry on Friday 7th of August 2009 01:54:49 AM
Old 08-07-2009
Code:
echo "abcde bangalo country 12345 lastfield" | sed 's/\(...\)\([^ ]* \)\(...\)\([^ ]* \)/\1\2\3\4\1\3 /'

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sorting on two fields time field and number field

Hi, I have a file that has data in it that says 00:01:48.233 1212 00:01:56.233 345 00:09:01.221 5678 00:12:23.321 93444 The file has more line than this but i just wanted to put in a snippet to ask how I would get the highest number with time stamp into another file. So from the above... (2 Replies)
Discussion started by: pat4519
2 Replies

2. Shell Programming and Scripting

awk script to (un)/concatenate fields in file

Hi everyone, I'm trying to use the "join" function for more than 1 field. Since it's not possible as it is, I want to take my input files and concatenate the joining fields as 1 field (separated by "|"). I wrote 2 awk script to do and undo it (see below). However I'm new to awk and I'm certain I... (5 Replies)
Discussion started by: anthony.cros
5 Replies

3. Shell Programming and Scripting

Count number of occurences of a character in a field defined by the character in another field

Hello, I have a text file with n lines in the following format (9 column fields): Example: contig00012 149606 G C 49 68 60 18 c$cccccacccccccccc^c I need to count the number of lower-case and upper-case occurences in column 9, respectively, of the... (3 Replies)
Discussion started by: s052866
3 Replies

4. Shell Programming and Scripting

AWK : Add Fields of lines with matching field

Dear All, I would like to add values of a field, if the lines match in a certain field. Then I would like to divide the sum though the number of lines that have a matched field. This is the Input: Input: Test1 5 Test1 10 Test2 2 Test2 5 Test2 13 Test3 4 Output: Test1 7.5 Test1 7.5... (6 Replies)
Discussion started by: DerSeb
6 Replies

5. Shell Programming and Scripting

Concatenate last field values for all occurences

Hello all, Maybe you can help me with an awk script to get what I need. I have the input file with format below: REQUEST|79023787741690|738227864597|985 REQUEST|79024002151717|738229423534|985 REQUEST|79024002151717|738229423534|*985 NDS-REQUEST|79024002151717|738229423534 ... (4 Replies)
Discussion started by: Ophiuchus
4 Replies

6. Shell Programming and Scripting

How to print 1st field and last 2 fields together and the rest of the fields after it using awk?

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

7. Shell Programming and Scripting

Display combination of 4 field uniqe record and along with concatenate 5th and 6th field.

Table ACN|NAME|CITY|CTY|NO1|NO2 115|AKKK|ASH|IND|10|15 115|AKKK|ASH|IND|20|20 115|AKKK|ASH|IND|30|35 115|AKKK|ASH|IND|30|35 112|ABC|FL|USA|15|15 112|ABC|FL|USA|25|20 112|ABC|FL|USA|25|45 i have written shell script using cut command and awk programming getting error correct it and add... (5 Replies)
Discussion started by: udhal
5 Replies

8. Shell Programming and Scripting

Inserting a field without disturbing field separator on other fields

Hi All, I have the input as below: cat input 032016002 2.891 97.109 16.605 27.172 24.017 32.207 0.233 0.021 39.810 0.077 0.026 19.644 13.882 0.131 11.646 0.102 11.449 76.265 23.735 16.991 83.009 8.840 91.160 0.020 99.980 52.102 47.898 44.004 55.996 39.963 18.625 0.121 1.126 40.189... (15 Replies)
Discussion started by: am24
15 Replies

9. Shell Programming and Scripting

sed to add field heards to specific fields

I have tab delimited input that prints out in the format below: I am trying to add field headers to $5 and $6. Not sure if sed is the best tool but my attempt is below. Thank you :). $5 = REF $6 = ALT file ID CHR START STOP 123 1 100 200 A ... (6 Replies)
Discussion started by: cmccabe
6 Replies

10. Shell Programming and Scripting

awk to add plus or minus to fields and split another field

In the tab-delimited input below I am trying to use awk to -10 from $2 and +10 to $3. Something like awk -F'\t' -v OFS='\t' -v s=10 '{split($4,a,":"); print $1,$2-s,$3+s,a,$5,$6} | awk {split(a,b,"-"); print $1,$2-s,$3+s,b-s,b+s,$5,$6}' input should do that. I also need to -10 from $4... (2 Replies)
Discussion started by: cmccabe
2 Replies
SUBSTR_COMPARE(3)							 1							 SUBSTR_COMPARE(3)

substr_compare - Binary safe comparison of two strings from an offset, up to length characters

SYNOPSIS
int substr_compare (string $main_str, string $str, int $offset, [int $length], [bool $case_insensitivity = false]) DESCRIPTION
substr_compare(3) compares $main_str from position $offset with $str up to $length characters. PARAMETERS
o $main_str - The main string being compared. o $str - The secondary string being compared. o $offset - The start position for the comparison. If negative, it starts counting from the end of the string. o $length - The length of the comparison. The default value is the largest of the length of the $str compared to the length of $main_str less the $offset. o $case_insensitivity - If $case_insensitivity is TRUE, comparison is case insensitive. RETURN VALUES
Returns < 0 if $main_str from position $offset is less than $str, > 0 if it is greater than $str, and 0 if they are equal. If $offset is equal to or greater than the length of $main_str, or the $length is set and is less than 1 (prior to PHP 5.6), substr_compare(3) prints a warning and returns FALSE. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.6.0 | | | | | | | $length may now be 0. | | | | | 5.1.0 | | | | | | | Added the possibility to use a negative $offset. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 A substr_compare(3) example <?php echo substr_compare("abcde", "bc", 1, 2); // 0 echo substr_compare("abcde", "de", -2, 2); // 0 echo substr_compare("abcde", "bcg", 1, 2); // 0 echo substr_compare("abcde", "BC", 1, 2, true); // 0 echo substr_compare("abcde", "bc", 1, 3); // 1 echo substr_compare("abcde", "cd", 1, 2); // -1 echo substr_compare("abcde", "abc", 5, 1); // warning ?> SEE ALSO
strncmp(3). PHP Documentation Group SUBSTR_COMPARE(3)
All times are GMT -4. The time now is 07:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy