How to select a single string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to select a single string
# 1  
Old 06-15-2011
How to select a single string

I am learning sed/awk. So, bear with me.

I have successfully created a list (based on sed) which looks like:

<cl:item href="clsysrev/XTT004/XTT05064.xml" productSubtitle="animals" unitStatus="today"IR">
<cl:item href="clsysrev/XTT007/XTT08581.xml" productSubtitle="humans" unitStatus="new" unitType="IR" iconStatus="true">
<cl:item href="clsysrev/XTT007/XTT08502.xml" productSubtitle="humans" unitStatus="new" unitType="IR">
<cl:item href="clsysrev/XTT004/XTT05063.xml" productSubtitle="animals" unitStatus="journal">
<cl:item href="clsysrev/XTT003/XTT04331.xml" productSubtitle="humans" unitStatus="edited (no change to conclusions)" unitType="IR">

My objective now is to create a list like:

XTT05064
XTT08581
XTT08502
XTT05063
XTT04331

The command I am trying to use is:

sed -e "s/\/XTT*xml$/p" myfile.txt > finalfile.txt

but I got stuck, and could not figure out how to get it done.

grateful for any tips.

Alonso
# 2  
Old 06-15-2011
One of the sed solution..
Code:
sed 's/.*\/\(.*\).xml.*/\1/' inputfile > outfile

# 3  
Old 06-15-2011
Code:
 
bash-3.00$ nawk -F"[\/|\"]" '{print substr($4,1,length($4)-4)}' /tmp/myfile
XTT05064
XTT08581
XTT08502
XTT05063
XTT04331

# 4  
Old 06-15-2011
Thank you very much for your time. both suggestions worked like a charm.

Cheers!

Alonso
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To get a single string in output

I am looking forward to achive below expecrted result, but when I am trying i could now get the whole string between two / / what I am getting is the last word i need to take complete line which is between / / ignore the line after , and before / which is (Test failed: text expected not to... (8 Replies)
Discussion started by: mirwasim
8 Replies

2. Programming

Query to SELECT only Column Names that Contain a Specific String?

Hey Guys, I'm using SQuirreL SQL v3.5 GUI to fetch some data that I need for something I'm working on. I'm also using the IBM Informix Driver (*Version 3.5) to connect to the Database. What I want to do, if it's even possible, is to show all COLUMNS if they contain the word "Email". So in... (2 Replies)
Discussion started by: mrm5102
2 Replies

3. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

4. UNIX for Dummies Questions & Answers

select and replace only those string which is followed by \tab

Hi I have a number of sequences and a string occurs a number of times in that sequence. How can I select and replace only those strings which are followed by \tab. for eg : my sequence looks like : string0 positive cd parent=string0 id =121 string0 string0 negative ef parent=... (2 Replies)
Discussion started by: sonia102
2 Replies

5. Shell Programming and Scripting

replace (sed?) a single line/string in file with multiple lines (string) from another file??

Can someone tell me how I can do this? e.g: Say file1.txt contains: today is monday the 22 of NOVEMBER 2010 and file2.txt contains: the 11th month of How do i replace the word NOVEMBER with (5 Replies)
Discussion started by: tuathan
5 Replies

6. Shell Programming and Scripting

how to test input variable is a string in a select loop

Okay -- I hope I ask this correctly. I'm working on my little shell script to write vendor names and aliases to files from user input. If a user choose to add to a file, he can do that as well. I'm using a select loop for this function to list all the possible files the user can choose from.... (7 Replies)
Discussion started by: Straitsfan
7 Replies

7. Shell Programming and Scripting

Select a specific part of the string and print it

Hi all, I have a string that looks like: #!/bin/sh options="arguments: --user=alpha --group=beta --prefix=/usr/share --proxy-path=/proxy --proxy-tmp=/tmp --conf-path=/etc" My goal is to transform the string into an array, then for each key, if it starts with "--proxy" to print the string... (2 Replies)
Discussion started by: TECK
2 Replies

8. Shell Programming and Scripting

How to select only the most frequent instances of a variable string in a file?

I've got a web access file that I want to grep (or awk or perl or whatever will work!) out the most frequent instances of unique IP entries. Meaning the file looks something like this: I'd like to run a sort or grep (or whatever) that will only select out the lines from IP's that had the... (7 Replies)
Discussion started by: kevinmccallum
7 Replies

9. Shell Programming and Scripting

Select particular string using AWK

Hi all, i searched this forum for the awk help i needed but i couldnt get any thread matching to my problem, My problem is i have a file file1 { <Server CloneID="13k6equ4c" Name="EnterpriseServicesClone2"> <Server CloneID="13k6eqvi1" Name="EnterpriseServicesClone1"> ... (7 Replies)
Discussion started by: usha rao
7 Replies

10. Shell Programming and Scripting

How to select the path that contains a certain string from a certain file?

Hi, I am new to this world of shell programming. I am facing a problem that is : I have directory which has many sub directories at different depth. say A/B/C/files A/B/files A/B/C/D/files In this directory structure there exists a file called ".project" in some of the sub... (2 Replies)
Discussion started by: bhaskar_m
2 Replies
Login or Register to Ask a Question