How to combine two string into one?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to combine two string into one?
# 8  
Old 02-21-2010
Hi,

radoulov's solution is exactly what i wanted. the order of the values is not important at all. Thanks for all the help given to me. I'm totally new in C-Shell, AWK, perl, etc. I'll try all the solution given and let you guys know the outcome. really appreciate your help

Regards,
SL

---------- Post updated at 07:20 PM ---------- Previous update was at 07:07 PM ----------

Hi,

the script work just nice. But i encounter a problem.
Code:
file1: z= /a:/b:/c
file2: z= /b:/c:/d

after using awk -f merge.awk file1 file2
the result i get is something like this:
Code:
z=/a::/b
/c
/d

is it the "/" is causing the problem here? because i tested the script with the following and it works perfectly.
Code:
file1 : z=a:b:c:d
file2 : z=b:c:d:e

Code:
result : z=a:b:c:d:e

Thanks in advance.
SL

Last edited by radoulov; 02-22-2010 at 05:55 AM.. Reason: Please use code tags!
# 9  
Old 02-22-2010
Hm,
I've just tested it and it seams to work as expected:
Code:
$ head file[12]
==> file1 <==
z= /a:/b:/c

==> file2 <==
z= /b:/c:/d
$ cat merge.awk 
BEGIN { FS = " *= *" }
END {
  printf "%s = ", f
  for (k in s) printf "%s", k \
    (j++ < n ? ":" : RS)
  }
{
  n = split($2, t, ":"); f = $1
  for (i = 0; ++i <= n;) s[t[i]]
  n > m && m = n
  }
$ awk -f merge.awk file1 file2
z = /a:/b:/c:/d

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combine files

I have n of files with ending with _ZERO.txt need to combine all file ending with _ZERO.txt into 1 file ex: A_ZERO.txt 1 2 B_ZERO.txt 3 4 Output: FINAL.txt 1 2 (3 Replies)
Discussion started by: satish1222
3 Replies

2. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

3. Shell Programming and Scripting

Combine 2 lines

All, i am new to linux script... source Filter: vlan281-BUM-5M BUM-5M 0 0 Filter: vlan282-BUM-5M BUM-5M 0 0 Filter: vlan2828-BUM-5M Filter:... (2 Replies)
Discussion started by: samoptimus
2 Replies

4. UNIX for Dummies Questions & Answers

Combine multiple files with common string into one new file.

I need to compile a large amount of data with a common string from individual text files throughout many directories. An example data file is below. I want to search for the following string, "cc_sectors_1" and combine all the data from each file which contains this string, into one new... (2 Replies)
Discussion started by: GradStudent2010
2 Replies

5. UNIX for Dummies Questions & Answers

combine -A and -v in grep

I have a data file that looks like this: infile: A 13 Z 23 F 22 Z 413 R 16how do I combine the -A option with the -v option to get the lines that don't match 'Z' and their next lines? the outfile should be: A 13 F 22 R 16I tried: (1 Reply)
Discussion started by: jdhahbi
1 Replies

6. Shell Programming and Scripting

combine

Dear all i am having text file like xxx|yyy|1|2| zzz|rrr|3|4| www|xxx|>< 5|6|>< jjj|kkk|>< 8|9>< i want to join two lines which are having ' >< ' by taking only two lines at a stretch ...using awk command the result output should be xxx|yyy|1|2| zzz|rrr|3|4| www|xxx|5|6|... (2 Replies)
Discussion started by: suryanarayana
2 Replies

7. Shell Programming and Scripting

perl combine if

Hi Evereyone, %q = (); $q{"a"} = 0; $q{"b"} = 0; $q{"c"} = 0; if ($q{"a"} !=0 || $q{"b"} !=0 || $q{"c"} !=0) { print "non-zero" } if any simple way to do that? assume you have not only a, b, c inside %q, but a, b, c, d, e, ... ... Thanks (2 Replies)
Discussion started by: jimmy_y
2 Replies

8. Shell Programming and Scripting

combine

Hi I am having text file like this 001|ramu|hno221|>< sheshadripuram|delhi|560061>< 002|krishna|hno225|>< newdelhimain|delhi|560061>< i want to combine every two lines as single...line... i.e 001|ramu|hno221|sheshadripuram|delhi|560061 can u pls help me (3 Replies)
Discussion started by: suryanarayana
3 Replies

9. Shell Programming and Scripting

Combine multiple string into 1 string group by certain criteria

Hi all, I am newbie in unix. Just have some doubts on how to join multiple lines into single line. I have 1 file with following contents. R96087641 HostName-kul480My This is no use any more %% E78343970 LocalPath-/app/usr/SG (Blank in this line) %% E73615740... (4 Replies)
Discussion started by: whchee
4 Replies

10. Shell Programming and Scripting

Combine files with same name

I need a script that combines files with the same name. These files are on a windows directory but the PC has Cygwin so i have a limited unix command set. What I've got; WebData_9_2007-09-20.txt WebData_9_2007-09-20.txt WebData_9_2007-09-21.txt WebData_9_2007-09-20.txt... (4 Replies)
Discussion started by: jmwhitford
4 Replies
Login or Register to Ask a Question