*** Truncate certain field ***


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users *** Truncate certain field ***
# 1  
Old 08-14-2007
Error *** Truncate certain field ***

I have a file in which I need to truncate 15th field to have only one character

like Put --> P

and if i have no value in 15th field, it should be "O" (Other)

would really appreciate the reponses, thnx in advanceSmilie
# 2  
Old 08-14-2007
Here is a pointer .

It would be better if you could post a sample input and output if this is not what you are looking for

Code:
cat 3
start|end|first
another||quick

Code:
awk -F"|" 'BEGIN{OFS="|"} { if ( length($2) ) { $2 = substr($2, 0, 1) } else { $2 = "O" } print }' 3
start|e|first
another|O|quick


Last edited by matrixmadhan; 08-14-2007 at 02:51 PM.. Reason: better output
# 3  
Old 08-15-2007
Thanks mate, works pretty well that's exactly wat I was looking for
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Truncate or Roundoff a calculation

Hi friends, I have a file of this kind chr1 3180929 3181465 48 chr1 3196182 3196586 26 chr1 3343498 3343814 25 chr1 3351126 3351383 16 I did some calculations on the 4th column using the following command. chr1 3180929 3181465 48 2.94665e-061000000... (4 Replies)
Discussion started by: jacobs.smith
4 Replies

2. UNIX for Dummies Questions & Answers

recover the truncate file

hi All, how to recover the truncate file in unix. Thanks!:wall: (2 Replies)
Discussion started by: krbala1985
2 Replies

3. Shell Programming and Scripting

Truncate Log files

Hi Gurus, I have several log files running in real time and needs to be truncated 50% or all but has to keep the logs piling up. Any ideas? For example: /var/adm/messages and others apps log files Thanks in advance! (7 Replies)
Discussion started by: anonymous1
7 Replies

4. Shell Programming and Scripting

Truncate table

Hi In unix able to connect to oracle database and create table ,when rerun ,if table exist ,truncate that table.Any idea how to do that a.sh ---- sqlplus -s datadmin/password <<EOF create table xx(col1 number, col2... ); exit; EOF I... (1 Reply)
Discussion started by: mohan705
1 Replies

5. UNIX for Dummies Questions & Answers

How can i truncate filenmes?

I am using FC6 just in case it matters, though i hope it doesn't. If i have a file or some files that i want to truncate the filename of, so that it is only a certain number of characters in length, how would i do that on the command line? Also, just to make it more interesting, say i... (11 Replies)
Discussion started by: Calum
11 Replies

6. Shell Programming and Scripting

Truncate File contain

I have one file which first line is blank and second line has some data. $cat filename output: 30-MAY-07 I want to store 30-MAY-07 value in one variable. for that I wrote var="`head -2 filename`" It will give that result but I want to truncate the first line which is blank. plz help. (2 Replies)
Discussion started by: rinku
2 Replies

7. Shell Programming and Scripting

Loop through and truncate tables

Hi, I was working on the truncate oracle table shell script. The script is supplied with one table name as a parameter and I would like to change it so that it is passed a file name with a list of tables. And the script needs to truncate tables one by one by looping through the file. In other... (10 Replies)
Discussion started by: madhunk
10 Replies

8. Shell Programming and Scripting

How to truncate as filesize?

Hello everybody it's me again. I have a procces that is writing in a 'file1' automatically but i want to truncate 'file1' to a filesize 'x' that mean if the 'file1' size is 'x' i want to delete the first lines while the last lines are being writed, that have sence? in the process are an... (1 Reply)
Discussion started by: Lestat
1 Replies

9. UNIX for Dummies Questions & Answers

truncate wtmp

I have AIX5.1 I have been trying to learn how to truncate the /var/adm/wtmp file. I have seen several things on google actually but don't quite understand. I also searched your forums but couldn't find it. one says this ">/var/adm/wtmp Is that all I do? I have a seperate question also. I was... (1 Reply)
Discussion started by: rocker40
1 Replies

10. UNIX for Dummies Questions & Answers

Truncate what is It?

what does this command do ? as in does this command just make sure everything in the file is executed? or does it flush the file? Actually this is used on a file in a progress database but I believe it is a unix command? (2 Replies)
Discussion started by: rocker40
2 Replies
Login or Register to Ask a Question