Sponsored Content
Top Forums Shell Programming and Scripting Concatenate text between patterns in individual strings Post 302649375 by Prev on Thursday 31st of May 2012 08:43:22 AM
Old 05-31-2012
Concatenate text between patterns in individual strings

In any given file, wherever a certain data block exists I need to concatenate the values(text after each "=" sign) from that block. in that block. The block starts and ends with specific pattern, say BEGIN DS and END DS respectively. The block size may vary. A file will have multiple such blocks. So say if there are 6 such blocks then I need 6 strings which have data in those respective blocks. Kindly guide.

Eg. "$file" has content :
Code:
 
Some lines of 
text
Begin DS
var1=some
var2=text 2 b concatenated 
End DS 
some more 
data
Begin DS
var1=some more
var2=text
var3=2 concatenate in 
var4=next string
End DS
:
:
so on

OUTPUT :::
Code:
 
text 2 b concatenated 
some more text 2 concatenate in next string
:

I know how to use sed for this if the block size was fixed ...

Last edited by Scrutinizer; 06-01-2012 at 04:53 AM.. Reason: code tags instead of quote tags
 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to concatenate two strings or several strings into one string in B-shell?

like connect "summer" and "winter" to "summerwinter"? Can anybody help me? thanks a lot. (2 Replies)
Discussion started by: fontana
2 Replies

2. Shell Programming and Scripting

patterns between strings...

I have a small requirement How to get patterns between string this way Input.. 05 ABC. TAGTAG 10 AAA PIC 9 10 BBB PIC X COMMET 10 CCC COMP PIC 9 05 DEF I wanted to get all the variable between 05 ABC and next 05 level out put should be AAA BBB (6 Replies)
Discussion started by: pbsrinivas
6 Replies

3. UNIX for Dummies Questions & Answers

Concatenate Strings

Hi Friends, I have a requirement I need to concatenate the below two strings. String 1 = /@jobid_at_ String 2 = value stored in ORACLE_SID String 3 = string1 concatenated with String 2. Please let me know how should i do it in UNIX. Thanks, (2 Replies)
Discussion started by: diva_thilak
2 Replies

4. UNIX for Dummies Questions & Answers

concatenate strings

if i use echo "ravi" echo "sankar" it showing output ravi sankar but i want output as ravi sankar remember sankar should be in another echo statement only (2 Replies)
Discussion started by: shankr3
2 Replies

5. Web Development

Concatenate Strings

hi..:) this is my sample part of my program.. $csv_output .= $row.",". $row.",". $row.",". $row.",". $row.",". ... (2 Replies)
Discussion started by: Jeneca
2 Replies

6. Programming

Concatenate two strings

Hello! Can anyone explain line 28 for me? I was thinking *a would be replaced by *b, but it actually appends *a to *b. I know it is related to pointer address, but could not figure it out by myself. Thanks a lot! 1 //Concatenate two strings 2 3 #include<stdio.h> 4 char *stradd (char *,... (5 Replies)
Discussion started by: yifangt
5 Replies

7. Shell Programming and Scripting

Concatenate strings

Hi,I'm trying to concatenate @example.com to each line of a file f1.txt. and push it into f2.txt. Here is the code i'm using. for i in `cat /home/linux1/xxxxxxx/f1.txt`; do echo ${i}@example.com > /home/linux1/xxxxxx/f2.txt; done But above code only printing @example.com in f2.txt. what... (18 Replies)
Discussion started by: sam_bd
18 Replies

8. UNIX for Dummies Questions & Answers

Concatenate strings in a a for loop

hi guys, I have this question. I am creating an script to that read a text file(.ini) with the list of the patterns to find for example: EPMS_VO EMPS_PARTS Then it check if file have been delivered in a folder and process it with each pattern, but I am having problems concatenting the... (7 Replies)
Discussion started by: Danman
7 Replies
Tcl_Concat(3)						      Tcl Library Procedures						     Tcl_Concat(3)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_Concat - concatenate a collection of strings SYNOPSIS
#include <tcl.h> CONST char * Tcl_Concat(argc, argv) ARGUMENTS
int argc (in) Number of strings. CONST char * CONST argv[](in) Array of strings to concatenate. Must have argc entries. _________________________________________________________________ DESCRIPTION
Tcl_Concat is a utility procedure used by several of the Tcl commands. Given a collection of strings, it concatenates them together into a single string, with the original strings separated by spaces. This procedure behaves differently than Tcl_Merge, in that the arguments are simply concatenated: no effort is made to ensure proper list structure. However, in most common usage the arguments will all be proper lists themselves; if this is true, then the result will also have proper list structure. Tcl_Concat eliminates leading and trailing white space as it copies strings from argv to the result. If an element of argv consists of nothing but white space, then that string is ignored entirely. This white-space removal was added to make the output of the concat command cleaner-looking. The result string is dynamically allocated using Tcl_Alloc; the caller must eventually release the space by calling Tcl_Free. | SEE ALSO
| Tcl_ConcatObj | KEYWORDS
| concatenate, strings | Tcl 7.5 Tcl_Concat(3)
All times are GMT -4. The time now is 12:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy