Sponsored Content
Full Discussion: Extract text from string
Top Forums Shell Programming and Scripting Extract text from string Post 302696685 by Lord Spectre on Wednesday 5th of September 2012 09:35:43 AM
Old 09-05-2012
Quote:
Originally Posted by pamu
I am not getting what's problem with your bash..Smilie

here i am getting perfect...

Code:
$ cat file3.sh
INFO="INFO : ABCDEFG"
echo "AAA ; BBB ; CCC ; $INFO DDD"

$ ./file3.sh
AAA ; BBB ; CCC ; INFO : ABCDEFG DDD

and in your previous post also... If you are getting $INFO right it should work for all the scenarios..Smilie
Wait, this works for me:
Code:
INFO="INFO : ABCDEFG"
echo "AAA ; BBB ; CCC ; $INFO DDD"

# ./test.sh 
AAA ; BBB ; CCC ; INFO : ABCDEFG DDD

I believe the problem is on sed!

---------- Post updated at 08:30 AM ---------- Previous update was at 08:26 AM ----------

Quote:
Originally Posted by zaxxon
I can't reproduce the problems you have neither with bash nor ksh - maybe show what your test.sh contains when being executed and producing the wrong output.

Also please post the type of shell you are using, thanks.
I test both with bash and with ksh.
You cannot reproduce since the test.sh create a specific command, then ftp that command on remote machine (OpenVMS), then execute it.
The output will be stored on /info.tmp file and is something like:

Code:
       AAAAAAAAAAAAAA
       BBBBBBBBBBBBBBB
       CCCCCCCCCCCCCCC
       DDDDDDDDDDDDDD
       INFO: ABCDEFG
       FFFFFFFFFFFFFFFFFF
       GGGGGGGGGGGGGG
......
......

Do you think the problem is on output file that contains some "dirty" chars??

---------- Post updated at 08:35 AM ---------- Previous update was at 08:30 AM ----------

WAIT, PROBLEM SOLVED!!!!

Aa I thought, the output file contains "dirty chars", this will solve the issue:
Code:
dos2unix -a /info.tmp > /dev/null 2>&1

Code:
# ./test.sh 
AAA ; BBB ; CCC ; INFO : ABCDEFG ; DDD

Thanks all for solution, all of them work! Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to extract text from string using regular expressions

Hi, I'm trying to use sed to extract some text and assign it to a variable. Can anyone provide me with some help? it would be much appreciated! I"m looking to extract for example: filename=/output/R34/2005_13_R34_C1042S_T83_CRFTXT_20081015.txt I'm trying to extract the 1042... (9 Replies)
Discussion started by: jtung
9 Replies

2. Programming

c program to extract text between two delimiters from some text file

needa c program to extract text between two delimiters from some text file. and then storing them in to diffrent variables ? text file like 0: abc.txt ========= aaaaaa|11111111|sssssssssss|333333|ddddddddd|34343454564|asass aaaaaa|11111111|sssssssssss|333333|ddddddddd|34343454564|asass... (7 Replies)
Discussion started by: kukretiabhi13
7 Replies

3. Shell Programming and Scripting

Search for string in a file and extract another string to a variable

Hi, guys. I have one question: I need to search for a string in a file, and then extract another string from the file and assign it to a variable. For example: the contents of the file (group) is below: ... ftp:x:23: mail:x:34 ... testing:x:2001 sales:x:2002 development:x:2003 ...... (6 Replies)
Discussion started by: daikeyang
6 Replies

4. Shell Programming and Scripting

how to extract a paticular string from the text file with awk.

hello forum members I have txt file which consists the following information. Server: abababa.xyz.ap.mxmx.com Address: 111.143.211.202 Name: rmxd.ipc.ap.mxmx.com Address: 144.111.99.9 from the abovefile i have to extract only string "rmxd.ipc.ap.mxmx.com" through awk command.... (1 Reply)
Discussion started by: rajkumar_g
1 Replies

5. Shell Programming and Scripting

to extract string from main string and string comparison

continuing from my previous post, whose link is given below as a reference https://www.unix.com/shell-programming-scripting/171076-shell-scripting.html#post302573569 consider there is create table commands in a file for eg: CREATE TABLE `Blahblahblah` ( `id` int(11) NOT NULL... (2 Replies)
Discussion started by: vivek d r
2 Replies

6. Shell Programming and Scripting

Extract a string between 2 ref string from a file

Hi, May i ask if someone share some command for extracting a string between 2 ref string in a txt file My objective: i had a file with multiple lines and wants only to extract the string "watch?v=IbkAXOmEHpY" or "watch?v=<11 random character>", when i used "grep 'watch?=*' i got a results per... (4 Replies)
Discussion started by: jao_madn
4 Replies

7. Shell Programming and Scripting

How to extract text from STRING to end of line?

Hi I have a very large data file with several hundred columns and millions of lines. The important data is in the last set of columns with variable numbers of tab delimited fields in front of it on each line. Im currently trying sed to get the data out - I want anything beetween :RES and... (4 Replies)
Discussion started by: Manchesterpaul
4 Replies

8. Shell Programming and Scripting

Search String and extract few lines under the searched string

Need Assistance in shell programming... I have a huge file which has multiple stations and i wanted to search particular station and extract few lines from it and the rest is not needed Bold letters are the stations . The whole file has multiple stations . Below example i wanted to search... (4 Replies)
Discussion started by: ajayram_arya
4 Replies

9. Shell Programming and Scripting

To Search for a string and to extract the string from the text

Hi Team I have an huge xml where i need to search for a ceratin numbers. For example 2014-05-06 15:15:41,498 INFO WebContainer : 10 CommonServicesLogs - CleansingTriggerService.invokeCleansingService Entered PUBSUB NOTIFY MESSAGE () - <?xml version="1.0" encoding="UTF-8"... (5 Replies)
Discussion started by: Kannannair
5 Replies

10. Shell Programming and Scripting

Extract all text between the same matching string from a given column

Hello All, I have an input sample data like below (In actual I have many columns and few million rows). Column1,Column2 4,2 1,5 Hello,4 1,4 Hello,2 3,5 Hello,8 4,5 Need the output (using awk and/or sed preferably) like below. Here I need all the lines between 2 matching... (1 Reply)
Discussion started by: ks_reddy
1 Replies
All times are GMT -4. The time now is 12:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy