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 : OUTPUT :::
I know how to use sed for this if the block size was fixed ...
Last edited by Scrutinizer; 06-01-2012 at 05:53 AM..
Reason: code tags instead of quote tags
Thanks both of you .. brilliant. Can you kindly explain your solution? It would be really helpful if there is slight change in the format of input file, plus , I am interested.
Thanks both of you .. brilliant. Can you kindly explain your solution? It would be really helpful if there is slight change in the format of input file, plus , I am interested.
Sure.
Explanantion:
Set "=" as field separator
If the line begins with the word "Begin" set variable s to NOTHING (dummy variable x=empty)
If there are 2 fields (records with a "=") then if s is not empty then s=s OFS $2 or s=$2
OFS is the output field separator, a built-in variable. The default value is a space.
If The line begins with the word "End" and s is not empty print s
Great. Thanks. So, to concatenate all data(not jst the part after =) in a block (all lines b/w Begin .. and end .. line ) , I tried with
but it doesnt work ... Please guide again.
Last edited by Scrutinizer; 06-01-2012 at 07:11 AM..
Reason: quote tags -> code tags
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)
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)
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)
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)
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)
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)