Updating entire column irrespective of any data in a file


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Updating entire column irrespective of any data in a file
# 1  
Old 10-04-2008
Updating entire column irrespective of any data in a file

Hi,

I have a file A.txt (tab separated) as below:

pavan chennai/tes/bangalore 100
sunil mangalore/abc/mumbai 230
kumar delhi/nba/andhra 310


I want to change only second column as below . Rest of columns as it is ;The ouput file is also tab separated.

pavan chennai/###/bangalore 100
sunil angalore/###/mumbai 230
kumar delhi/###/andhra 310

Please let me know how to do this in unix script. I am using ksh shell
Thanks in advance
# 2  
Old 10-04-2008
If you have something like pavan tab chennai/tes/bangalore tab 100, then:
Code:
echo -e "pavan\tchennai/tes/bangalore\t100"|perl -ne 'print if (s/^(.*?\t.*?\/).*?(\/.*?\t.*?)$/$1###$2/g);'
or cat file_with_those_lines | perl -ne 'print if (s/^(.*?\t.*?\/).*?(\/.*?\t.*?)$/$1###$2/g);'

# 3  
Old 10-04-2008
Thanks .....Smilie

It is working but present working directory path is appending at the end of last line in the file .


pavan chennai/tes/bangalore 100
sunil mangalore/abc/mumbai 230
kumar delhi/nba/andhra 310[servername] /path/


Please suggest me .

Alos if there are many columns in a files is there a way give range like $2- $100 .
# 4  
Old 10-04-2008
With sed:

Code:
sed 's_\(.*/\).*\(/.*\)_\1###\2_' file > newfile

Regards
# 5  
Old 10-04-2008
if you have PHP
Code:
<?php
$file = "file";
$data=file($file);
foreach($data as $k=>$v){
  $v=explode("/",$v);
  $v[1]="###";
  $v=implode("/",$v);
  echo "$v";
}
?>

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Input file needs to match a column and print the entire line

I have a file with class c IP addresses that I need to match to a column and print the matching lines of another file. I started playing with grep -if file01.out file02.out but I am stuck as to how to match it to a column and print the matching lines; cat file01.out 10.150.140... (5 Replies)
Discussion started by: lewk
5 Replies

2. Shell Programming and Scripting

Remove entire line from a file if 1st column matches a pattern

I have one requirement to delete all lines from a file if it matches below scenario. File contains three column. Employee Number, Employee Name and Employee ID Scenario is: delete all line if Employee Number (1st column) contains below 1. Non-numeric Employee Number 2. Employee Number that... (3 Replies)
Discussion started by: anshu ranjan
3 Replies

3. UNIX for Dummies Questions & Answers

Fill csv entire column with content from another text file

I have a csv that looks like this: ,yude-to-nap2,0,0,0,0,0 ,2twis-yude-to-nap2,0,0,0,0,0 ,2tiws-yude-to-nap2,0,0,0,0,0 ,2arcos-yude-to-nap2,0,0,0,0,0 and another file named m1 that has a single line of text as content: Feb 1 15:30:20 How can I fill the whole the empty column of the... (1 Reply)
Discussion started by: RobertoRivera
1 Replies

4. Shell Programming and Scripting

Delete an entire column from a tab delimited file

Hi, Can anyone please tell me about how we can delete an entire column from a tab delimited file? Mu input_file.txt looks like this: And I want the output as: I used the below code nawk -v d="1" 'BEGIN{FS=OFS="\t"}{$d=""}{print}' input_file.txtBut in the output, the first column is... (5 Replies)
Discussion started by: sampoorna
5 Replies

5. Programming

updating data in cvs file using c programming

hi every one i want to read and write data from cvs file using c program. but my problem is that at run time my data is increasing in both row wise and column wise. that means it is continuously updating in both direction. is there any way through which i can find the next colum or row for eg... (0 Replies)
Discussion started by: sajidtariq
0 Replies

6. Shell Programming and Scripting

logrotate irrespective of the size of a file/directory

hi, How to logrotate irrespective of the size of a file/directory...? Please help me in this regard... (4 Replies)
Discussion started by: Dedeepthi
4 Replies

7. Shell Programming and Scripting

Updating the data from one file to the other

Hi, Somebody please assist me in updating the data from one file to the other in Shell Scripting. There are two files file1 and file2. Both the files have differen data but a common attribute. e.g. JAVA_HOME. e.g. file1 has JAVA_HOME=/usr/j2se and file2 has... (3 Replies)
Discussion started by: Santosh251982
3 Replies

8. Shell Programming and Scripting

edit entire column from a fixed-width file using awk or sed

Col1 Col2 Col3 Col4 12 Completed 08 0830 12 In Progress 09 0829 11 For F U 07 0828 Considering the file above, how could i replace the third column the most efficient way? The actual file size is almost 1G. I am... (10 Replies)
Discussion started by: tamahomekarasu
10 Replies

9. Shell Programming and Scripting

Awk+Grep Input file needs to match a column and print the entire line

I'm having problems since few days ago, and i'm not able to make it works with a simple awk+grep script (or other way to do this). For example, i have a input file1.txt: cat inputfile1.txt 218299910417 1172051195 1172070231 1172073514 1183135117 1183135118 1183135119 1281440202 ... (3 Replies)
Discussion started by: poliver
3 Replies

10. Shell Programming and Scripting

To cut entire column from a file and apend it to another file as another column

file1.txt : india pakistan bangladesh japan canada africa USA srilanka Nepal file2.txt Delhi Tokyo washington I have to cut the first column of file1.txt and apend it with file2.txt as another column like this Delhi india Tokyo japan washington USA ... (4 Replies)
Discussion started by: sakthifire
4 Replies
Login or Register to Ask a Question