sed for all columns


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers sed for all columns
# 1  
Old 08-28-2015
sed for all columns

Hi,

I would like to know how can I use sed in all columns of a file tab separated.

Example of input file:
Code:
0/0:0:1,0,0  0/2:0:0,2,0

Desired output file:
Code:
1,0 0,2


Last edited by Don Cragun; 08-28-2015 at 06:02 PM.. Reason: Add CODE tags.
# 2  
Old 08-28-2015
You need to remember to use CODE tags and you need to clearly describe the edits that you are trying to make to your file using sed. Note that neither of your tab separated sample files contain any tabs.
# 3  
Old 08-28-2015
With sed, try:
Code:
sed 's/[^:]*:[^:]*:\([^,]*,[^,]*\)/\1 /g; s/ [^ ]*$//'  file

--
Alternatively with awk:
Code:
awk '{for(i=1; i<=NF; i++) {sub(/.*:/,x,$i); sub(/,[^,]*$/,x,$i)}}1'  file

or
Code:
awk '{for(i=1; i<=NF; i++) {split($i,F,"[/:,]"); $i=F[4]","F[5]}}1' file

# 4  
Old 08-29-2015
Got Perl?
Code:
perl -nle '@m = /:(\d,\d)/g and print "@m"' file

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add specific text to columns in file by sed

What is the proper syntax to add specific text to a column in a file? Both the input and output below are tab-delineated. What if there are multiple text/fields, such as /CP&/2 /CM&/3 /AA&/4 Thank you :). sed 's/*/Index&/1' del.txt.hg19_multianno.txt > matrix.del.txt (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

Merge 2 last columns in a csv file using sed or perl

Hello everyone, want to merge 2 last columns 3rd and 4rd (if it exists). I have this 1;2;1;1 2;3;1;1 1;1;2 1;2;3;4 1;1;2 1;2;3;1 Desired output: 1;2;1 1 2;3;1 1 1;1;2 1;2;3 4 1;1;2 1;2;3 1 (3 Replies)
Discussion started by: satir
3 Replies

3. UNIX for Dummies Questions & Answers

Sed: delete columns 7,15,16

An extension from an earlier question. Now need a sed script to delete columns 7,15 and 16 from an example txt below.. Again, thanks in advance. 98M-01.WAV,98M,01,00:00:49,01:07:36:00,"MIX",,"BOOM-MKH50",,,,,,,,,,"", 98L-01.WAV,98L,01,00:00:51,01:01:45:00,"MIX",,"BOOM-MKH50",,,,,,,,,,"", (7 Replies)
Discussion started by: Vrc2250
7 Replies

4. Shell Programming and Scripting

sed cut columns

hello everyone ! i face the following problem as i use sed to ignore some columns of an output. the command i use is sed 's/^\(*\) \(*\).*/\1 \2/' as i only want the 2 first columns the command finger returns the problem is that for some lines the results are fine but for other lines... (8 Replies)
Discussion started by: vlm
8 Replies

5. Shell Programming and Scripting

Manipulate columns using sed

Hello, I would like to remove the first column of lines beginning by a character (in my case is an open square bracket) and finishing by a space (or any other delimiter). For example: string1 string2 string3 to string2 string3 I found this previous topic: ... (1 Reply)
Discussion started by: stoyanova
1 Replies

6. Shell Programming and Scripting

Selecting specific 'id's from lines and columns using 'SED' or 'AWK'

Hello experts, I am new to this group and to 'SED' and 'AWK'. I have data (text file) with 5 columns (C_1-5) and 100s of lines (only 10 lines are shown below as an example). I have to find or select only the id numbers (C-1) of specific lines with '90' in the same line (of C_3) AND with '20' in... (6 Replies)
Discussion started by: kamskamu
6 Replies

7. Shell Programming and Scripting

AWK or SED for correct columns

Hello, I have the following file, but one of his columns is not in place, and tried with SED and AWK, how I can correct format? In the second line break is wrong, and puts it after the first column of next line I would appreciate if you could guide me on the subject. (4 Replies)
Discussion started by: nitwh
4 Replies

8. Shell Programming and Scripting

using sed to get rid of duplicated columns...

I can not figure out this one, so I turn to unix.com for help, I have a file, in which there are some lines containing continuously duplicate columns, like the following adb abc abc asd adfj 123 123 123 345 234 444 444 444 444 444 23 and the output I want is adb abc asd adfj 123 345... (5 Replies)
Discussion started by: fedora
5 Replies

9. UNIX for Dummies Questions & Answers

Using 'sed' to delete or ignore columns in a dataset

Hi, I want to know if its possible to delete or ignore columns in a large dataset using 'sed'. For example, I have the following dataset: - 20060714,X.XX,1,043004,Q,T,24.0000,1,25.5000,4, 20060714,X.XX,1,081209,Q,T,24.0000,1,25.5000,5, As you can see, there are 10 columns here and the... (4 Replies)
Discussion started by: aarif
4 Replies

10. UNIX for Dummies Questions & Answers

Using 'sed' to delete or ignore columns in a dataset

Hi, I've already posted elsewhere but am posting again here coz im a newbie. I hope you forgive me this time. I want to know if its possible to delete or ignore columns in a large dataset using 'sed'. For example, I have the following dataset: - ... (0 Replies)
Discussion started by: aarif
0 Replies
Login or Register to Ask a Question