Extract string between two delimiter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract string between two delimiter
# 8  
Old 08-13-2013
@Pratik Majithia
Quote:
change( ) to " "
This will make it more complicate to know where to start/stop. Please post a complete example of the real file.

@R. Singh
Code:
awk '
	{
	v=$0			# stor line $0 in variable v
	gsub(/.*\(|\).*/,x,v)	# remove all text before "(" and after ")" in variable v
	s=s?s OFS v:v		# if s does not exist s=v, if s exist append v to s using OFS a separator s=s OFS v (This prevent a blank space in front of line)
	}
	/\./ {			# if line does contain a "." we are on last line.
		print s		# print the created s
		s=""		# clear s
		}
	' file

This User Gave Thanks to Jotne For This Post:
# 9  
Old 08-13-2013
Quote:
Originally Posted by RudiC
Try
Code:
awk '{while (!($0~/\.... *$/)) {getline x;$0=$0" "x}}{gsub (/^[^(]*\(|\).*$/,"")}1' file
January
January February March April June July
January febuary march  april may

Could you please explain me how this command works??

Thanks is advance
# 10  
Old 08-13-2013
Changing RudiCs code we can do this regarding () is changed to ""
Code:
cat file
2007_08_07_IA-0100-014_"January".PDF
2007_08_07_IA-0100-031_"January February March
April June July".PDF
2008-02-28_KR-1022-003_"January
febuary
march april
may".CSV


Code:
awk -F\" '{while ($0!~/\./) {getline x;$0=$0" "x}} {print $2}'
January
January February March April June July
January febuary march april may


Last edited by Jotne; 08-13-2013 at 06:31 AM..
# 11  
Old 08-13-2013
Modified post#3 RudiC's solution
Code:
awk '{while (!($0~/\.... *$/)){getline x;$0=$0" "x}gsub(/.*_"|".*/,y)}1' infile

--ahamed
# 12  
Old 08-13-2013
---------- Post updated at 03:33 PM ---------- Previous update was at 03:33 PM ----------

Thank you, Code is working fine with above file, but i have another file, and this code is not work with this file, I want to extract data from this file,
INPUT FILE
Code:
db2 +c "alter table $SCHEMA.$tabname activate not logged initially" >>$LOG 2>&1
db2 +c "alter table $SCHEMA.$tabname activate not logged initially & 
$SCHEMA.$tabname activate not logged initially JOIN
$SCHEMA.$tabname activate not logged initially INNER
$SCHEMA.$tabname activate not logged initially" >>$LOG 2>&1
db2 +c "alter table $SCHEMA.$tabname activate not logged initially" >>$LOG 2>&1
db2 +c "alter table $SCHEMA.$tabname 
activate not logged initially" >>$LOG 2>&1

And I want data between two delimeter " " in one line only.

Last edited by Franklin52; 08-13-2013 at 07:24 AM.. Reason: Please use code tags
# 13  
Old 08-13-2013
Each command/solution we give is coded for a different pattern. If you come with new patterns every time and say that it is not working, I don't think we can do much!
Try to understand the solutions which are given and extend/modify for your needs.

--ahamed
# 14  
Old 08-13-2013
just check both the file are same, just content was different.
but still code is not working.
It's not a different pattern.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract multiple columns base on double quotes as delimiter

Hi All, I have my data like below "1","abc,db","hac,aron","4","5" Now I need to extract 1,2,4th columns Output should be like "1",abc,db","4" Am trying to use cut command but not able to get the results. Thanks in advance. (4 Replies)
Discussion started by: weknowd
4 Replies

2. Shell Programming and Scripting

Skip the delimiter with in double quotes and count the number of delimiters during data extract

Hi All, I'm stuck-up in finding a way to skip the delimiter which come within double quotes using awk or any other better option. can someone please help me out. Below are the details: Delimited: | Sample data: 742433154|"SYN|THESIS MED CHEM PTY.... (2 Replies)
Discussion started by: BrahmaNaiduA
2 Replies

3. Shell Programming and Scripting

how to cut all string after the last delimiter?

hi all, suppose a string: abc/def/ghi/jkl/mn.txt and i want to get the file name without the path. however, different files have different paths, therefore the number of delimiter is uncertain. thanks so much! (3 Replies)
Discussion started by: sunnydanniel
3 Replies

4. Shell Programming and Scripting

How to split a string with no delimiter

Hi; I want to write a shell script that will split a string with no delimiter. Basically the script will read a line from a file. For example the line it read from the file contains: 99234523 These values are never the same but the length will always be 8. How do i split this... (8 Replies)
Discussion started by: saint34
8 Replies

5. Shell Programming and Scripting

Extract semicolon separated delimiter

The log reads as follows. fname1;lname1;eid1;addr;pincode1; fname2;lname2;eid2;addr2;pincode2; fname3;lname3;eid3;addr3;pincode3; fname4;lname4;eid;addr4;pincode4; how do i extract only fname and save it in an array similarly for lname and so on i tried reading a file and cutting each... (5 Replies)
Discussion started by: vkca
5 Replies

6. Shell Programming and Scripting

Extract 2 or more int from the text with delimiter.

Hi All, I want to extract the integers from the each line, each line may have 2 or more integers. The following command is appending each integers. echo "Hi I am 100, my friend is 500, his friend is 423" | sed "s///g" 100500423 I need to have delimiter "|" between the integers. If anyone... (18 Replies)
Discussion started by: sarwan
18 Replies

7. Shell Programming and Scripting

extract string from varying delimiter line

Hi I have lines like this a=1, b=2, c=3, a=1, d=4, e=5, b=225, I need to extract the b=nnn... value. I dont know how many other entries will be before and after it in each line. Ive tried a basic line like awk '/b=/, $NF ~ /,/ ' myfile.txt but I think that it doesnt care which comma it... (5 Replies)
Discussion started by: rebelbuttmunch
5 Replies

8. Shell Programming and Scripting

Delimiter count in a string.

Hi , I need to get the delimiter "-" count in a particular string. string= SYS_NAME-123-S5-2008-10-20.LOG the delimit "-" count is 5 . Using sed or awk can I know the count ? I have seen how to get the count for delimiter in a file but not a string :( Thanks, Priya (8 Replies)
Discussion started by: priyam
8 Replies

9. UNIX for Dummies Questions & Answers

extract fields from text file using delimiter!!

Hi All, I am new to unix scripting, please help me in solving this assignment.. I have a scenario, as follows: 1. i have a text file(read1.txt) with the following data sairam,123 kamal,122 etc.. 2. I have to write a unix... (6 Replies)
Discussion started by: G.K.K
6 Replies

10. Shell Programming and Scripting

creating a delimiter string

hi i have a function printValues() { var=$# count=0 qName="" while do if then echo QManager Name $1 fi if then echo Cluster Name$2 fi if (( $count != 0 && $count != 1 )) then ... (0 Replies)
Discussion started by: satish@123
0 Replies
Login or Register to Ask a Question