Extracting Complete Text Between " "


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting Complete Text Between " "
# 1  
Old 01-25-2010
Extracting Complete Text Between " "

The script:
Code:
for i in $(awk '/\".*\"/' list.txt)
do
   echo $i
done

iist.txt:
Code:
"Willie"
"Willie Willie"
"Willie Willie Wee"
"Willie Willie Wee Wee"

The results:
Code:
"Willie"
"Willie
Willie"
"Willie
Willie
Wee"
"Willie
Willie
Wee
Wee"

I'm needing this though:
Code:
Willie
Willie Willie
Willie Willie Wee
Willie Willie Wee Wee

# 2  
Old 01-25-2010
hello try this,

Code:
gaurav@localhost:~$ echo '"Willie"
"Willie Willie"
"Willie Willie Wee"
"Willie Willie Wee Wee"' | perl -wln -e 'print $1 if /"(.*)"/'
Willie
Willie Willie
Willie Willie Wee
Willie Willie Wee Wee
gaurav@localhost:~$

Regards,
Gaurav.
# 3  
Old 01-25-2010
What about:
Code:
sed 's/"//g' list.txt

# 4  
Old 01-25-2010
Code:
tr -d '"' < file

# 5  
Old 01-25-2010
It seems that the suggestions above work if I run them from a terminal but in my script I get something different.

As an example:

tr -d '"' < list.txt

gets me what I am looking for.

Willie
Willie Willie
Willie Willie Wee
Willie Willie Wee Wee

However:

for i in $(tr -d '"' < list.txt)
do
echo $i
done

gets me:

Willie
Willie
Willie
Willie
Willie
Wee
Willie
Willie
Wee
Wee

So, I guess from what I am getting I probably have something else incorrect in my script and I am probably instructing incorrectly for what I am wanting.

The eventual intent of this script is to loop through the chain of names in the list and alter files elsewhere that are applicable to each name . That's all figured out but I just cannot extract the names correctly to correctly alter those files elsewhere.
# 6  
Old 01-25-2010
Code:
OLD_IFS=$IFS
IFS=""
for i in $(tr -d '"' < file)
do
echo $i
done
IFS=$OLD_IFS

# 7  
Old 01-25-2010
Code:
while read line
do 
  eval echo "$line"
done < list.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. UNIX for Dummies Questions & Answers

Extracting Parts of String "#" vs "%"

Hello, I have a question regarding extracting parts of a string and the meaning of # and % in the syntax. I created an example below. # filename=/first/second/third/fourth # # echo $filename /first/second/third/fourth # # echo "${filename##*/}" fourth # # echo "${filename%/*}"... (3 Replies)
Discussion started by: shah9250
3 Replies

3. Shell Programming and Scripting

Using sed to find text between a "string " and character ","

Hello everyone Sorry I have to add another sed question. I am searching a log file and need only the first 2 occurances of text which comes after (note the space) "string " and before a ",". I have tried sed -n 's/.*string \(*\),.*/\1/p' filewith some, but limited success. This gives out all... (10 Replies)
Discussion started by: haggismn
10 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

Extracting text with "nawk"

Hi - I have a simple file (x.xml): <tag1>text 1</tag1> <tag2>text 2</tag2> <tag3>text 3</tag3> <tag4>text 4</tag4> <tag5>text 5</tag5> I am trying to run a simple nawk script against it in order to get the text contained within the tags: nawk 'BEGIN{FS=""} /tag1/{tag1=$3}... (3 Replies)
Discussion started by: nfr816
3 Replies

6. Shell Programming and Scripting

grep "226 Transfer complete" | wc -l

echo $ftp_ctr returns '0' instead of '1'. Please help 331 Enter password 230 User logged in 200 Transfer mode set to BINARY local: file1 remote: file2 227 Entering Passive Mode (xxxxxxxx). 125 Uploading in BINARY file xxx 226 Transfer completed 24453780 bytes sent in 67 seconds... (9 Replies)
Discussion started by: Lenora2009
9 Replies

7. Shell Programming and Scripting

read -p "prompt text" foo say "read: bad option(s)" in Bourne-Shell

Hallo, i need a Prompting read in my script: read -p "Enter your command: " command But i always get this Error: -p: is not an identifier When I run these in c-shell i get this error /usr/bin/read: read: bad option(s) How can I use a Prompt in the read command? (9 Replies)
Discussion started by: wiseguy
9 Replies

8. Shell Programming and Scripting

Extracting a text between ""

Hi, I am having trouble extracing a string between the quotes. The OS in solaris 8 I have a directory which has solaris packages and i need to do pkginfo for all and search for uninstalled packages. #ls -l drwxr-xr-x 5 root other 512 Apr 14 17:41 SUNWxwplx drwxr-xr-x ... (14 Replies)
Discussion started by: Jartan
14 Replies

9. UNIX for Dummies Questions & Answers

Convert "text" to "packed-decimal"?

Is there a way with HP-UX Release 10.20 (but going to HP-UX 11) to convert a regular "text" file to a packed data format (such as is created by a Cobol program)? (2 Replies)
Discussion started by: HuskyJim
2 Replies
Login or Register to Ask a Question