Extracting data from between double quotes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting data from between double quotes
# 1  
Old 08-30-2013
Code Extracting data from between double quotes

Need assistance , Below is the data between double code .

Code:
</td><td><a href="geavg.t00z.pgrb2af18">geavg.t00z.pgrb2af18</a>

Below commands gives me the result but i want everything in one command using single nawk

Code:
 nawk -v RS="< href" -F">" '/t00z/ { print $1 }' ucar.output | nawk -F '"' '{print $2}'

result i need
Code:
geavg.t00z.pgrb2af18


Last edited by ajayram_arya; 08-30-2013 at 06:04 PM..
# 2  
Old 08-30-2013
Hello,

Could you please use the following code.
Let us say a is the variable which have input given by you.

Code:
a=`echo </td><td><a href=geavg.t00z.pgrb2af18>geavg.t00z.pgrb2af18</a>`

Code:
echo $a | awk -F"\>" '{print$4}' | sed 's/\<\/a//g'

Output will be as follows.


Code:
geavg.t00z.pgrb2af18



Thanks,
R. Singh

Last edited by RavinderSingh13; 08-30-2013 at 06:21 PM.. Reason: littile change...
# 3  
Old 08-30-2013
A sed alternative:
Code:
$ sed 's/.*href="\([^"]*\).*/\1/' file
geavg.t00z.pgrb2af18

# 4  
Old 08-30-2013
RavinderSingh13

My code below works ,I cannot take that code into a variable since its a huge file which i am trying to get geavg.t00z.pgrb2af18 files and many more like this

Code:
nawk -v RS="< href" -F">" '/t00z/ { print $1 }' ucar.output | nawk -F '"' '{print $2}'

i want to use only one nawk instead of two nawk. let me know if there is a better way .
# 5  
Old 08-31-2013
Then you should give us the file ucar.output and example on output.
This way we could help you without guessing.
# 6  
Old 08-31-2013
What about
Code:
awk -F"\"" '/t00z/ {print $2}' file

?
# 7  
Old 09-01-2013
Just using string manipulation...

Code:
var='</td><td><a href="geavg.t00z.pgrb2af18">geavg.t00z.pgrb2af18</a>'
var1="${var##*href\=\"}"
var2="${var1%\"\>*}"
echo "$var2"

output
Code:
geavg.t00z.pgrb2af18

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace double quotes inside the string data for all the columns

Please use code tags Hi, I have input data is below format and n of column in the multiple flat files. the string data has any double quotes(") values replaced to double double quotes for all the columns{""). Also, my input flat file each column string data has carriage of new line too.... (14 Replies)
Discussion started by: SSrini
14 Replies

2. Shell Programming and Scripting

Replace Double quotes within double quotes in a column with space while loading a CSV file

Hi All, I'm unable to load the data using sql loader where there are double quotes within the double quotes As these are optionally enclosed by double quotes. Sample Data : "221100",138.00,"D","0019/1477","44012075","49938","49938/15043000","Television - 22" Refurbished - Airwave","Supply... (6 Replies)
Discussion started by: mlavanya
6 Replies

3. 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

4. Shell Programming and Scripting

Handling embedded double quotes within column data

I have a text file where each field is enclosed in double quotes and separated by a comma. But in certain rows we have embedded double quotes within column data For e.g """TRUSPICE CENTRE"" CLAYTON AU" The above value is for a single column but there are embedded quotes within... (2 Replies)
Discussion started by: abhilashnair
2 Replies

5. Shell Programming and Scripting

Issue with Single Quotes and Double Quotes for prompt PS1

Hi, Trying to change the prompt. I have the following code. export PS1=' <${USER}@`hostname -s`>$ ' The hostname is not displayed <abc@`hostname -s`>$ uname -a AIX xyz 1 6 00F736154C00 <adcwl4h@`hostname -s`>$ If I use double quotes, then the hostname is printed properly but... (3 Replies)
Discussion started by: bobbygsk
3 Replies

6. Shell Programming and Scripting

Extract data based on 2nd colume having double quotes

i want extract where the 2nd column having "3" or "7". Based on the forums tried like this but it is not working awk -F"," '$2=3;$2=7 {print}' filename Source "1","2","3","4" "1","3","3","4" "1","7","3","4" "1","8","3","4" "1","2","3","4" "1","2","3","4" Output : ... (5 Replies)
Discussion started by: onesuri
5 Replies

7. UNIX for Dummies Questions & Answers

grep single quotes or double quotes

Unix superusers, I am new to unix but would like to learn more about grep. I am very familiar with regular expressions as i have used them for searching text files in windows based text editors. Since I am not very familiar with Unix, I dont understand when one should use GREP with the... (2 Replies)
Discussion started by: george_vandelet
2 Replies

8. Shell Programming and Scripting

Single quotes and double quotes

Hi guys, I have a sed line in double quotes which works fine, but I want it to be in single quotes here is the sed line sed "/abc_def/s/\'.*\'/\'\${abc_def}\'/" can some one give the equivalent to the above script in single quotes Thanks a ton (5 Replies)
Discussion started by: sol_nov
5 Replies

9. Shell Programming and Scripting

Double quotes or single quotes when using ssh?

I'm not very familiar with the ssh command. When I tried to set a variable and then echo its value on a remote machine via ssh, I found a problem. For example, $ ITSME=itsme $ ssh xxx.xxxx.xxx.xxx "ITSME=itsyou; echo $ITSME" itsme $ ssh xxx.xxxx.xxx.xxx 'ITSME=itsyou; echo $ITSME' itsyou $... (3 Replies)
Discussion started by: password636
3 Replies

10. Shell Programming and Scripting

comparing scalars contaning "DOUBLE QUOTES" as data

Hello to all, Does anyone know the solution ? Two strings A and B are present. I want to check whether B is a Substring of A. 1. The value of A is - 29 * * * /bin/ls "test" "tmp*" "log*" (Note: Pl note that A contains DOUBLEQUOTES, ASTERISK & FRONTSLASH) 2. The value of B is -... (5 Replies)
Discussion started by: rssrik
5 Replies
Login or Register to Ask a Question