Simple Cut issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple Cut issue
# 1  
Old 03-24-2010
Simple Cut issue

I have a long string that looks something like this....
Code:
	<string>http://abc.com/40/20/zzz061-3472/dP3rXLpPPV2KC846nJ4VXpH7jt4b3LJgkL/tarfile_date.tar</string>

I need to but the tar file name. So I need to put between "/" and ".tar</string>". My desired result should be "tarfile_date".
# 2  
Old 03-24-2010
Try this :

Code:
echo "<string>http://abc.com/40/20/zzz061-3472/dP3rXLpPPV2KC846nJ4VXpH7jt4b3LJgkL/tarfile_date.tar</string>" |rev | 
awk -F '.' '{print $2}' | awk -F '/' '{print $1}' | rev


Last edited by Franklin52; 03-24-2010 at 01:49 PM.. Reason: Please use code tags.
# 3  
Old 03-24-2010
Or:

Code:
basename `sed -e 'sX<string>XXg' filename.txt|sed -e 'sX</string>XXg'`| awk -F '.' '{print $1'}

tarfile_date

Eliminate the XML delimiiters <string> and </string> to simplify the problem, then use "basename" to find the last string after the last "/". Then use awk to separate "tarfile_date" from "tarfile_date.tar".
# 4  
Old 03-24-2010
Or:
Code:
echo $string | sed 's!.*/\(.*\)\..*!\1!'

# 5  
Old 03-24-2010
Quote:
Originally Posted by Franklin52
Or:
Code:
echo $string | sed 's!.*/\(.*\)\..*!\1!'


Can you explain the above command execution.
# 6  
Old 03-24-2010
Quote:
Originally Posted by Jairaj
Can you explain the above command execution.
Code:
sed 's!.*/\(.*\)\..*!\1!'

The command saves the part \(.*\) between the last slash .*/ and the last dot ..* and recall it as \1
# 7  
Old 03-24-2010
Code:
echo $string | grep -o -e '[^/.]*\.tar' | cut -d'.' -f1

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue with CUT command

Hi All, I am facing an issue while cutting fields with comma delimiter. There are many records with Double quotes in between. My data: aaa,bbb,"ccc, ddd",eee,fff,"ggg ,hhh",iii When i use cut command with comma delimiter, i am getting wrong data like field1=aaa field2=bbb field3="ccc... (3 Replies)
Discussion started by: krishna_gnv
3 Replies

2. Shell Programming and Scripting

Cut command issue

Need help to append a pipe at end of the line immediately after the cut command, I have an Input flat file with 16 feilds and I am removing the 16th feild by using the cut command as shown, Input: 354|||||CORPORTATION||||NENE PARADE|||WISBECH|CAMBRIDGESHIRE|PE13 3BY|100001| I... (5 Replies)
Discussion started by: Aditya_001
5 Replies

3. Shell Programming and Scripting

Cut command issue with shell script

I am writing a shell script to skip couple of feilds in a flat file and as a part of this I have written the below piece of code in it. cut -d '|' -f 1-17,19-31 $1 > filename To add pipe at end of the line I used below command, but it adds even to header and footer as well which i... (11 Replies)
Discussion started by: Aditya_001
11 Replies

4. Shell Programming and Scripting

Issue with cut and paste

let i have A file and B file A has contains 4 fields as below ---------------- f1 f2 f3 f4 B file consists of 5 fields as below -------------------- f5 f6 f7 f8 f9 need to display as below output: f5 f1 f3 f8 f9 (2 Replies)
Discussion started by: ANSHUMAN1983
2 Replies

5. Shell Programming and Scripting

CUT Command and grep issue

I am trying to grep the oracle erros evry day from the logs file. My problem is : -rw-r----- 1 tibcolm tibco 17438361 Apr 5 11:59 RetryService-RetryService.log -rw-r----- 1 tibcolm tibco 245303 Apr 5 12:00 ResponseService-ResponseService.log -rw-r----- 1 tibcolm tibco 2122654 Apr 5 12:00... (4 Replies)
Discussion started by: neeraj617
4 Replies

6. Shell Programming and Scripting

cut command issue from a line of text

Hi, I got a line of text which has spaces in between and it is a long stream of characters. I want to extract the text from certain position. Below is the line and I want to take out 3 characters from 86 to 88 character position. In this line space is also a character. However when using cut... (5 Replies)
Discussion started by: asutoshch
5 Replies

7. Shell Programming and Scripting

Simple SED issue

Hi! I'm a newbie and can't find the exact sed to make this work. I've installed CentOS and am trying to pass variables to a network-config file. variables: $ipAddress $netmask $gateway file: DeviceList.Ethernet.eth0.IP=192.168.1.10 DeviceList.Ethernet.eth0.Netmask=255.255.255.0... (5 Replies)
Discussion started by: greipr
5 Replies

8. Shell Programming and Scripting

Simple Cut Question

I've got a file that contains a large list of links in this type of style: 'home_dir\2009\09\01\file.html' I'd like to cut off all of the characters left of 'file.html'. I tried: cat file.txt | cut -d\ -f4 but it told me that I had an invalid delimiter. So I tried: cat... (5 Replies)
Discussion started by: Rally_Point
5 Replies

9. UNIX for Advanced & Expert Users

simple issue..

I have a program. Everytime that I run that program ,it prints a disclaimer msg and prompts the user to accept the agreement (i.e: type 'y' or 'n'). Now I want to run the program multiple times with different inputs. So I wrote a script which runs in a loop and calls the program multiple times.... (2 Replies)
Discussion started by: the_learner
2 Replies

10. Shell Programming and Scripting

The cut command. Really simple question!

hi, sorry for asking what I am sure is a really easy question, I am wanting to cut the users real name from the output of 'finger'. $ cut -f2-3 filename is in my script but it only seems to cut the first line. I need to cut the 2nd and 3rd word from each line and store them in variables... (1 Reply)
Discussion started by: rorey_breaker
1 Replies
Login or Register to Ask a Question