How to clear last 5 characters from 14th field in a file?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to clear last 5 characters from 14th field in a file?
# 1  
Old 10-23-2013
How to clear last 5 characters from 14th field in a file?

Hi,
I have a file with 15 fields seperated by '|'. The requirement is to clear the last 5 characters of the 14th field. modifications should be done to the original file .

Can some one help me in sorting this out.
# 2  
Old 10-23-2013
try awk
Code:
awk -F '|'  '{$14=substr($14,1,length($14)-5) ; print}' oldfile > newfile

Run this to be sure you got the changes you wanted, then you can rename newfile to oldfile.
Code:
mv newfile oldfile

# 3  
Old 10-23-2013
Try:
Code:
perl -i -aF"\|" -pe '$F[13]=~s/.{5}$//;$_=join "|", @F' file

 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using awk to add length of matching characters between field in file

The awk below produces the current output, which will add +1 to $3. However, I am trying to add the length of the matching characters between $5 and $6 to $3. I have tried using sub as a variable to store the length but am not able to do so correctly. I added comments to each line and the... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

Stripping unwanted characters in field

I wrote myself a small little shell script to clean up a file I have issues with. In particular, I am stripping down a fully qualified host/domain name to just the hostname itself. The script works, but from a performance standpoint, it's not very fast and I will be working with large data sets. ... (4 Replies)
Discussion started by: dagamier
4 Replies

3. Shell Programming and Scripting

How to remove alphabets/special characters/space in the 5th field of a tab delimited file?

Thank you for 4 looking this post. We have a tab delimited file where we are facing problem in a lot of funny character. I have tried using awk but failed that is not working. In the 5th field ID which is supposed to be a integer only of that file, we are getting corrupted data as below. I... (12 Replies)
Discussion started by: Srithar
12 Replies

4. UNIX for Dummies Questions & Answers

awk if one field has more characters than another

Hi all, I've been stuck on how to write a command in awk that looks at two columns and only prints entries where one of the columns has more than or less than a 3 character difference. I need to be able to compare any two columns preferably, but as an example, comparing columns 3 and 4 example... (9 Replies)
Discussion started by: torchij
9 Replies

5. Shell Programming and Scripting

Remove the special characters from field

Hi, In source data few of columns are having special charates(like *) due to this i am not able to display the data into flat file.it's displaying the some of junk data into the flat file. source dataExample: Address1="XDERFTG * HYJUYTG" how to remove the special charates in a string (2 Replies)
Discussion started by: koti_rama
2 Replies

6. Shell Programming and Scripting

awk for presence of characters in a field

I have a text file like: "10","server","","11111",JLB, I need a way to say if the 3rd field has data in it, move the contents of the entire line to a new file. Any ideas? Thanks, (5 Replies)
Discussion started by: scriptr2be
5 Replies

7. Solaris

removing special characters, white spaces from a field in a file

what my code is doing, it is executing a sql file and the resullset of the query is getting stored in the text file in a fixed format. for that fixed format i have used the following code:: Code: awk -F":"... (2 Replies)
Discussion started by: priyanka3006
2 Replies

8. Shell Programming and Scripting

need to extract field of characters in a line

Hello, Below is my input file's content ( in HP-UX platform ): ABCD120672-B21 1 ABCD142257-002 1 ABCD142257-003 1 ABCD142257-006 1 From the above, I just want to get the field of 13 characters that comes after 'ABCD' i.e '120672-B21'... . Could you please let me know the shell script... (3 Replies)
Discussion started by: jansat
3 Replies
Login or Register to Ask a Question