removing last field of the line


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers removing last field of the line
# 1  
Old 12-11-2006
Data removing last field of the line

I have a text file containing

/database/sp/NTR_Vlr_Upload.sql
/database/tables/StatsTables.sql
/mib/ntr.mib
/mib/ntr.v2.mib
/scripts/operations/ntr/IMSITracer.ph


i want the last field after "/" removed like

/database/sp/
/database/tables/
/mib/
/mib/
/scripts/operations/ntr/

plz help
# 2  
Old 12-11-2006
Care to read the manpages ? Look at man dirname
# 3  
Old 12-11-2006
Code:
for line in `cat file.txt`; do dirname $i; done

# 4  
Old 12-11-2006
Are you looking for

cat file | awk -F "/" '{print $NF}'

??

Regds,

Kaps
# 5  
Old 12-11-2006
Ooops , you wanted

cat file | xargs -n1 dirname

Regds,

Kaps
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing line breaks inside a field

Hi all, I have a csv input file with total 60 fields and the fields are not enclosed with double quotes.One of the field(50th field) in this file has line breaks in it which results in the row getting split into multiple lines.This is causing my load(to table) to fail.I tried to enforce double... (3 Replies)
Discussion started by: Bobby_2000
3 Replies

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

3. Shell Programming and Scripting

Removing date field from the string

Hii I am trying to remove the date field from the following string. ODS_EPP_COVRG_STN_DETL_FILE_10032014.TXT. My output should be ODS_EPP_COVRG_STN_DETL_FILE.TXT I tried couple of things: echo ODS_EPP_COVRG_STN_DETL_FILE_10032014.TXT|sed 's/_*\.*//g' I am getting:... (9 Replies)
Discussion started by: skatpally
9 Replies

4. Shell Programming and Scripting

Removing duplicated first field rows

Hello, I am trying to eliminate rows where the first field is duplicated, leaving the row where the last field is "NET". Data file: 345234|22.34|LST 546543|55.33|LST 793929|98.23|LST 793929|64.69|NET 149593|49.22|LST Desired output: 345234|22.34|LST 546543|55.33|LST... (2 Replies)
Discussion started by: palex
2 Replies

5. Shell Programming and Scripting

removing a particular field from some of the lines in a filed

Hi All, i have a file having multiple lines but mainly constitues of following two types 1) Sat,Oct,1,01:04:51,2011,Local,ESSBASE0,Info(1051037),Logging,out,user,210073155,,,active,for,63,minutes,GETS_SAL,loaded 2)... (2 Replies)
Discussion started by: dev.devil.1983
2 Replies

6. Shell Programming and Scripting

sed to replace a field from a line with another field

i have something like this, cat filename.txt hui this si s"dfgdfg" omeone ipaddress="10.19.123.104" wel hope this works i want to replace only 10.19.123.104 with different ip say 10.19.123.103 i tried this sed -i "s/'ipaddress'/'ipaddress=10.19.123.103'/g" filename.txt ... (1 Reply)
Discussion started by: vivek d r
1 Replies

7. Shell Programming and Scripting

Compare Field in Current Line with Field in Previous

Hi Guys I have the following file Essentially, I am trying to find the right awk/sed syntax in order to produce the following 3 distinct files from the file above: Basically, I want to print the lines of the file as long as the second field of the current line is equal to the... (9 Replies)
Discussion started by: moutaye
9 Replies

8. UNIX for Dummies Questions & Answers

Removing spaces in the second field alone

Consider my input string as "abc|b f g|bj gy" I am expecting the output as "abc|bfg|bj gy". Please let me know how to achieve this in unix? Thanks (8 Replies)
Discussion started by: pandeesh
8 Replies

9. Shell Programming and Scripting

Removing duplicate field from MARC Record

Hello, I'm new to Perl programming and I have a duplicate 035 tag Voyager application field. The first 035 tag has the information I need but the second 035 tag created the bib id, which I don't need. This incident was performed on several records so I would have to run this script on several... (1 Reply)
Discussion started by: rcnick
1 Replies

10. Shell Programming and Scripting

Removing parts of a specific field

All, I have a field in a comma seperated file with hundreds of lines and about 20 columns and I wish to remove all numbers after the decimal point in field 4 on each line and output the rest to another file or write it back to itself. File is like this 20070126, 123.0, GBP, 1234.5678,... (9 Replies)
Discussion started by: kieranh
9 Replies
Login or Register to Ask a Question