how to cut a field of a line in a text file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to cut a field of a line in a text file?
# 1  
Old 03-12-2009
how to cut a field of a line in a text file?

Hi,
I have text file which contains lines like :
a/a/a/a/.project
b/b/b/b/b/.project
c/c/c/.project
d/.project
e/e/e/e/.project

i want for all lines the last word .project should be removed and the file should look like :

a/a/a/a/
b/b/b/b/b/
c/c/c/
....

how to proceed ? Please help. Thanks in advance.
# 2  
Old 03-12-2009
You can read the file line-by-line using xargs, replace the / by some other delimiter and then pass it to basename command for cutting the .project extension and then replace the delimiter in the output back to /

I tried it and it worked perfectly for me but need to make sure that the intermediate delimiter that you are using is not present anywhere else in the file or else that would also be converted to /
# 3  
Old 03-12-2009
cud u please list out the commands u have used?
# 4  
Old 03-12-2009
A combination of xargs, tr and basename. I do not want to give the whole command here since this question sounds like a homework question to me.
# 5  
Old 03-12-2009
It is not a homework question . I am facing this problem for building an application as a continous integration activity and this file acts as a configuration file. Anyways thanks for giving the idea, trying to implement.
# 6  
Old 03-12-2009
Code:
man dirname

# 7  
Old 03-12-2009
thats nice Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command/script to match a field and print the next field of each line in a file.

Hello, I have a text file in the below format: Source Destination State Lag Status CQA02W2K12pl:D:\CAQA ... (10 Replies)
Discussion started by: pocodot
10 Replies

2. Shell Programming and Scripting

Update specific field in a line of text file

I have a text file like this: subject1:LecturerA:10 subject2:LecturerA:40 if I was given string in column 1 and 2 (which are subject 1 and LecturerA) , i need to update 3rd field of that line containing that given string , which is, number 10 need to be updated to 100 ,for example. The... (6 Replies)
Discussion started by: bmtoan
6 Replies

3. Shell Programming and Scripting

Cut third field of every third line

Hello, I have got a log file and would need to write a script to cut the every first and second fields of every third line. Job Name : dummytextd_v1 Status : KILLED TIMEDOUT 2011-05-01 05:33 Job Name : dummyttx_v1 Status : KILLED TIMEDOUT 2011-05-03 02:33 Job Name :... (4 Replies)
Discussion started by: Kochappa
4 Replies

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

5. UNIX for Dummies Questions & Answers

Cut a field from a line having quotes as delimiter

Hi , I have extract a single field from the 2nd row of a file of which the format is as given below "Field1","Field2","Field3",...,"Field17",... I need to cut Field17 as such (no quotes required).. I give the command head -2 file_name | tail -1 | cut -d "," -f17 But the output is... (2 Replies)
Discussion started by: nivin_govindan
2 Replies

6. Shell Programming and Scripting

cut the second line in a text file

Hi I have some problem to cut out the second line in a output file and send to a new file it's a #!/bin/bash script 1 something 2 something 3 something and after I cut 1 something 3 something New file 2 something Thanks in advance (7 Replies)
Discussion started by: pelle
7 Replies

7. Shell Programming and Scripting

Help need to cut the first word of a line in text file

Hi All, I would like help with a script which can get rid of the first work of all lines in text file. File 1 The name is Scott. Output : name is Scott ---------- Post updated at 02:38 PM ---------- Previous update was at 02:37 PM ---------- Hi ALL There is typo error in... (3 Replies)
Discussion started by: bubbly
3 Replies

8. Shell Programming and Scripting

print line if 2nd field exists in text

2 files, first one has 3 fields seperated by ||| and 2nd one is plain text. I want to copy the lines from the first file if the 2nd field is present anywhere in the text file. This is what I've tried, but I'm new to awk and shell scripting in general so it's kinda broken. #!/bin/awk -f BEGIN... (15 Replies)
Discussion started by: FrancoisCN
15 Replies

9. Shell Programming and Scripting

How to cut first line only from a text near a specific column without cutting a word

First I have to say thank you to this community and this forum. You helped me very much builing several useful scripts. Now, I can't get a solution the following problem, I'm stuck somehow. Maybe someone has an idea. In short, I dump a site via lynx and pipe the output in a file. I need to... (7 Replies)
Discussion started by: lowmaster
7 Replies

10. Shell Programming and Scripting

Text cut between two $ in a line with SED

Let's say I have a line like that: I want to cut out numbers between two $ including $s. The result should be like that: I am so-newbei. I am non-stop reading about SED since yesterday and not a programmer. I know that it is a short period, thus maybe I had overlooked something. I... (4 Replies)
Discussion started by: l_p
4 Replies
Login or Register to Ask a Question