modify one column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting modify one column
# 1  
Old 06-16-2011
modify one column

Hi,

I have an output that looks unusual and it is very large so I cannot do it manually.

Basically it looks like this:


Code:
U	>c93[org=S_paradoxus][moltype=genomic][contig=c93]	57866	R
U	>c38[org=S_paradoxus][moltype=genomic][contig=c38]	66265	R
U	>c261[org=S_paradoxus][moltype=genomic][contig=c261]	80401	R
U	>c169[org=S_paradoxus][moltype=genomic][contig=c169]	12250	R
U	>c348[org=S_paradoxus][moltype=genomic][contig=c348]	2661	F
U	>c425[org=S_paradoxus][moltype=genomic][contig=c425]	38762	R
U	>c351[org=S_paradoxus][moltype=genomic][contig=c351]	44504	R
U	>c421[org=S_paradoxus][moltype=genomic][contig=c421]	8212	F
U	>c467[org=S_paradoxus][moltype=genomic][contig=c467]	3648	F
U	>c84[org=S_paradoxus][moltype=genomic][contig=c84]	33028	R
U	>c6[org=S_paradoxus][moltype=genomic][contig=c6]	4765	R

It is a tab separated file and I want it to modify the second column (basically simplify it) to look like this:

Code:
U	c93	57866	R
U	c38	66265	R
U	c261	80401	R
U	c169	12250	R
U	c348	2661	F
U	c425	38762	R
U	c351	44504	R
U	c421	8212	F
U	c467	3648	F
U	c84	33028	R
U	c6	4765	R

Thanks

Phil
# 2  
Old 06-16-2011
Code:
sed 's/<tab>.*contig=\(.*\)]/<tab>\1/' inp_file

# 3  
Old 06-16-2011
hi thanks for the post but it makes no change to the file.
# 4  
Old 06-16-2011
Code:
$ sed "s/\([^>]*\).*=\([^]]*\)]/\1\2/" file
U	 c93	57866	R
U	 c38	66265	R
U	 c261	80401	R
U	 c169	12250	R
U	 c348	2661	F
U	 c425	38762	R
U	 c351	44504	R
U	 c421	8212	F
U	 c467	3648	F
U	 c84	33028	R
U	 c6	4765	R

# 5  
Old 06-16-2011
Code:
awk -F"[\t>[]" '{print $1"\t"$3"\t"$(NF-1)"\t"$NF}'

# 6  
Old 06-16-2011
Code:
awk '{split($2,a,"[>|[]");print $1,a[2],$3,$4}' OFS="\t" infile

# 7  
Old 06-17-2011
Code:
 
sed 's/\>.*contig=//;s/]//g' infile

This User Gave Thanks to xoops For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If pattern match in other column, modify column 3.

My command sed will modify everything in column 3 if i will use the command below. I want to search for a pattern then modify everything in column 3. sed -i 's/\|165\|/server1/g' file.txt Input: 01-31-2019 19:14:05|device|165|1548962040165|5c5348f9-0804-1111|file_attach|7271|587|smtp|... (6 Replies)
Discussion started by: invinzin21
6 Replies

2. Shell Programming and Scripting

Ed to modify a file --- or not?

Running Oracle Linux 6 (derivative of RHEL 6) Given this snippet of code in a shell script: #-- reset oratab to use 11.2 home for dwdev #-- normally we'd just use sed to do this sort of thing, but that would #-- require permissions that we don't have in the /etc/ directory, so we #-- ... (3 Replies)
Discussion started by: edstevens
3 Replies

3. UNIX for Dummies Questions & Answers

Modify Column Data using Shell Script

HI Guys, Input :- P081 wr1 12p0d5: 22.8 P081 wr1 12p2d18: 23.1 P149 wr1 1pxcud6/port_0_dev_7: 20.4 P149 wr1 1pxcud4/port_1_dev_10: 22.4 OutputP081 wr1 120 22.8 P081 wr1 122 23.1 P149 wr1 10 20.4 P149 wr1 11 22.4 In in First two line delete p and after d untill : In Last two line... (4 Replies)
Discussion started by: pareshkp
4 Replies

4. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

5. Shell Programming and Scripting

Difference of the same column when two other column matches and one column differs less than 1 hour

This is my input file : # cat list 20130430121600, cucm, location,76,2 20130430121600,cucm1,location1,76,4 20130430122000,cucm,location,80,8 20130430122000,cucm1,location1,90,8 20130430140000,cucm1,location1,87,11 20130430140000, cucm,location,67,9 This is the required output ... (1 Reply)
Discussion started by: Lakshmikumari
1 Replies

6. Shell Programming and Scripting

Rename a header column by adding another column entry to the header column name URGENT!!

Hi All, I have a file example.csv which looks like this GrpID,TargetID,Signal,Avg_Num CSCH74_1_1,2007,61,256 CSCH74_1_1,212007,647,679 CSCH74_1_1,12007,3,32 CSCH74_1_1,207,299,777 I want the output as GrpID,TragetID,Signal-CSCH74_1_1,Avg_Num CSCH74_1_1,2007,61,256... (4 Replies)
Discussion started by: Vavad
4 Replies

7. Shell Programming and Scripting

modify first column

Hi, I am use to using awk and sed. This time I have a file that has multiple columns. It looks like this: 4 6 7 8 5 4 3 2 3 2 6 9 I want to add chr to column 1 only so it looks like this: chr4 6 7 8 chr5 4 3 2 chr3 2 6 9 The file is tab seperated. Thanks ... (5 Replies)
Discussion started by: phil_heath
5 Replies

8. Shell Programming and Scripting

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2 file 1 sample SNDK 80004C101 AT XLNX 983919101 BB NETL 64118B100 BS AMD 007903107 CC KLAC 482480100 DC TER 880770102 KATS ATHR 04743P108 KATS... (7 Replies)
Discussion started by: rydz00
7 Replies

9. Shell Programming and Scripting

how can I modify this script.

hello forum members, I have a script which is used find the Uname and passwords and redirects into a output.txt file.I hardcoded a string "ciadev" but iwant search two more strings also "absdev" and "absprod" So modify this script please. I am lookinmg forward from you, please find the below... (2 Replies)
Discussion started by: rajkumar_g
2 Replies

10. Shell Programming and Scripting

Changing one column of delimited file column to fixed width column

Hi, Iam new to unix. I have one input file . Input file : ID1~Name1~Place1 ID2~Name2~Place2 ID3~Name3~Place3 I need output such that only first column should change to fixed width column of 15 characters of length. Output File: ID1<<12 spaces>>Name1~Place1 ID2<<12... (5 Replies)
Discussion started by: manneni prakash
5 Replies
Login or Register to Ask a Question